MultidimensionalArray
DRAFT

Misconception:

When we allocate a multi-dimensional array e.g., with new int[x][y][z], one single array object is created, which directly provides space for all the elements.

Incorrect

A multi-dimensional array is one thing

Correct

A multi-dimensional is a structure of nested arrays

Correction
Here is what's right.

In Java, a multi-dimensional array is simply an array of arrays (of arrays, of arrays, of …). Thus:

int[][][] a3 = new int[4][5][6];
int[][]   a2 = a3[0];
int[]     a1 = a3[0][0];
int       i  = a3[0][0][0];

a3 is a three-dimensional array, but, really, it just is an array with 4 elements, each of the elements is of type int[][] (an array of array of int). So, a3 is an array which contains 4 references to 4 arrays, which each contains 5 references to 5 arrays, which each contain 6 ints. We assign the value of the 0th element of a3 to a2, which is a two-dimensional array.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.