Question: Consider:

```
int[][] multD = new int[5][];
multD[0] = new int[10];

```

Is this how you create a two-dimensional array with 5 rows and 10 columns?

I saw this code online, but the syntax didn't make sense.

Answer: 
We can declare a two dimensional array and directly store elements at the time of its declaration as:

```
int marks[][]={{50,60,55,67,70},{62,65,70,70,81},{72,66,77,80,69}};

```

Here *int* represents integer type elements stored into the array and the array name is 'marks'. *int* is the datatype for all the elements represented inside the "{" and "}" braces because an array is a collection of elements having the same data type. 

Coming back to our statement written above: each row of elements should be written inside the curly braces. The rows and the elements in each row should be separated by a commas.

Now observe the statement: you can get there are 3 rows and 5 columns, so the JVM creates 3 \* 5 = 15 blocks of memory. These blocks can be individually referred ta as:

```
marks[0][0]  marks[0][1]  marks[0][2]  marks[0][3]  marks[0][4]
marks[1][0]  marks[1][1]  marks[1][2]  marks[1][3]  marks[1][4]
marks[2][0]  marks[2][1]  marks[2][2]  marks[2][3]  marks[2][4]

```

NOTE:  

If you want to store *n* elements then the array index starts from zero and ends at *n-1*.
Another way of creating a two dimensional array is by declaring the array first and then allotting memory for it by using new operator.

```
int marks[][];           // declare marks array
marks = new int[3][5];   // allocate memory for storing 15 elements

```

By combining the above two we can write:

```
int marks[][] = new int[3][5];

```
If you want something that's dynamic and flexible (i.e. where you can add or remove columns and rows), you could try an "ArrayList of ArrayList":

```java
public static void main(String[] args) {

    ArrayList<ArrayList<String>> arrayListOfArrayList = new ArrayList<>();

    arrayListOfArrayList.add(new ArrayList<>(List.of("First", "Second", "Third")));
    arrayListOfArrayList.add(new ArrayList<>(List.of("Fourth", "Fifth", "Sixth")));
    arrayListOfArrayList.add(new ArrayList<>(List.of("Seventh", "Eighth", "Ninth")));
    arrayListOfArrayList.add(new ArrayList<>(List.of("Tenth", "Eleventh", "Twelfth")));

    displayArrayOfArray(arrayListOfArrayList);
    addNewColumn(arrayListOfArrayList);
    displayArrayOfArray(arrayListOfArrayList);
    arrayListOfArrayList.remove(2);
    displayArrayOfArray(arrayListOfArrayList);
}

private static void displayArrayOfArray(ArrayList<ArrayList<String>> arrayListOfArrayList) {
    for (int row = 0; row < arrayListOfArrayList.size(); row++) {
        for (int col = 0; col < arrayListOfArrayList.get(row).size(); col++) {
            System.out.printf("%-10s", arrayListOfArrayList.get(row).get(col));
        }
        System.out.println("");
    }
    System.out.println("");
}

private static void addNewColumn(ArrayList<ArrayList<String>> arrayListOfArrayList) {
    for (int row = 0; row < arrayListOfArrayList.size(); row++) {
        arrayListOfArrayList.get(row).add("added" + row);
    }
}

```

Output:

```
First     Second    Third     
Fourth    Fifth     Sixth     
Seventh   Eighth    Ninth     
Tenth     Eleventh  Twelfth   

First     Second    Third     added0    
Fourth    Fifth     Sixth     added1    
Seventh   Eighth    Ninth     added2    
Tenth     Eleventh  Twelfth   added3    

First     Second    Third     added0    
Fourth    Fifth     Sixth     added1    
Tenth     Eleventh  Twelfth   added3    

```