Create a 2D array
Here’s is how we can create multidimensional arrays:
Int[][] data = new int[3](4];
Here, data is a two-dimensional array where each 3 elements of the array is also an array that has 4 elements. Hence, the array can hold 12 elements in total.
Initialize Two Dimensional Arrays
Here is how we can initialize a 2D array.
Int[][] data = { {2, 3, 5},
{7, 14, 21, 28},
{3, 5, 7, 9} };
Here, data is a 2D array. We can see each element of the array is an array itself.
Similar to a one-dimensional array, we use indexes to access elements of a 2D array.