Java 2d Arrays
Arrays are not, but 2d arrays are confusing.
We basically know what is going on, but let’s clarify once more.
In short, first square brackets denote row number and the second denote column.
So let’s say we created an array with the code
int[][] array2D = new int[3][2];
and it will default as 0 values inside.
array2D[0][0] –> row 0, column 0.
array2D[0][1] –> row 0, column 1.
array2D[1][0] –> row 1, column 0.
array2D[1][1] –> row 1, column 1.
array2D[2][0] –> row 2, column 0.
array2D[2][1] –> row 2, column 1.
so just keep in mind that first is row, and second is column,
and also the actual arrays are 0-indexed, not 1-indexed in Java.
To be little more descriptive,
in above example, the actual array would look like something like
array2D = ((1, 2), (3, 4), (5, 6)); (don’t forget we should use curly braces, not just braces)
when initialized.
That means the rows would be inside the columns.
We can also see this as,
(int[]) []
which means that we are having an array of integer arrays,
which are rows of integers.
By this thought process, we can easily apprehend 3d, 4d, arrays as we can see them as arrays of arrays of arrays… of arra..y.