Multidimensional arrays syntax

Multidimensional arrays are created by specifying two or more pairs of square brackets in the declaration. Multi-dimensional arrays are created as arrays of arrays. The initialization takes place in the same way as one-dimensional arrays by specifying the number of elements per dimension. Multi-dimensional arrays can be accessed by specifying all required indices, each in their own square brackets. Even with multi-dimensional arrays, a literal initialization can be achieved by nesting the initialization sequences.

type[][] name = new type[2][4];
type[][] name = {{0, 1}, {0, 1, 2, 3}, {0, 1, 2, 3, 4}};
Code Explanation

The first line of code creates a 2D array named name with 2 rows and 4 columns of type type. The type could be any data type such as int, double, char, etc. This line of code initializes an empty 2D array with no values assigned.

The second line of code creates another 2D array named name but this time it initializes the array with values. The array has 3 rows and varying number of columns in each row, with the number of columns being different for each row. The values assigned to each element in the array are specified in the curly braces.