Question: I want to represent a board game in javascript and for that i need a bidimensional array.

I have different board sizes, so i need to initialize the array with the board size in the beginning. I am a java programmer so i know that in java when you want a bidimensional array you just do:

```
int board_size = 6;
String board = new String[board_size][board_size];

```

How can i achieve this with javascript? I have searched and found some ways of doing this, but all much less intuitive than this one.

Answer: 
> 
> Replace point with comma in a JTable causes a wrong sorting-sequence
> 
> 
> 

A little part of the problem is you are mixing up the data itself about how should it be displayed or rendered.

However the main problem IMHO is you don't override [getColumnClass(int columnIndex)](http://docs.oracle.com/javase/7/docs/api/javax/swing/table/TableModel.html#getColumnClass%28int%29) in your table model: I'd never trust in asking the model for the first row cells' classes. What if `getValueAt(0,1)` returns `null`? Answer: you'll get a `NullPointerException` at `getValueAt(0,1).getClass()` call.

Now given the context in your question you can't provide an appropriate `TableCellRenderer` because you don't know what class will the result set return beforehand. However you can rely on the default behavior described in [Concepts: Editor and Renderers](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender) and override `getColumnClass(...)` method to return a correct class using the [ResultSetMetaData](http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSetMetaData.html) as follows:

```
public TableModel getTableModel(ResultSet resultSet) throws SQLException {    
    ResultSetMetaData metaData = resultSet.getMetaData();        

    int columnCount = metaData.getColumnCount(); // columns number
    String[] columnNames = new String[columnCount];
    final Class[] columnClasses = new Class[columnCount];

    for (int i = 1; i <= columnCount; i++) {
        columnNames[i-1] = metaData.getColumnName(i); // fill columns names
        try {
            columnClasses[i-1] = Class.forName(metaData.getColumnClassName(i)); // fill column classes
        } catch (ClassNotFoundException ex) {
            // Log the exception here
        }
    }

    resultSet.last();
    int rowCount = resultSet.getRow(); // get rows number
    resultSet.beforeFirst();

    Object[][] data = new Object[rowCount][columnCount];
    int currentRow = 0;
    while (resultSet.next()) {
        for (int currentColumn = 1; currentColumn <= columnCount; currentColumn++) {
            data[currentRow][currentColumn - 1] = resultSet.getObject(currentColumn); // fill data set
         }
         currentRow++;
    }

    TableModel model = new DefaultTableModel(data, columnNames) {
        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return columnClasses[columnIndex];
        }
    }
    return model;    
}

```

**Note:** the use of `Object[]` instead of `Vector` is just because I had the code [somewhere else](https://stackoverflow.com/a/27062173/1795530) and I'm too lazy to modify it.
> 
> but then my Sorting-Sequence is not correct because the values will be sorted as a String instead of a BigDecimal...
> 
> 
> 

Don't store a String in the TableModel. Store the BigDecimal.

> 
> If I cast a BigDecimal to a String for replacing a point with a comma,
> 
> 
> 

Formatting the data is the job of the renderer. Check out [Table Format Renderers](https://tips4java.wordpress.com/2008/10/11/table-format-renderers/) for a simple example of how to override the `setValue(...)` method of the renderer.

You will also need to override the `getColumnClass(...)` method to return BigDecimal so the appropriate sort can be done.