OnlyInnermostArrayElements
DRAFT

Misconception:

In a multi-dimensional array like int[][][] a = new int[5][5][5], one has to specify indices of all dimensions to access an element (e.g., one can access a[1][1][1], but a[1][1] is illegal).

Incorrect

Only the elements of the innermost array of a multi-dimensional array are accessible

Correct

Also the elements of outer arrays of a multi-dimensional array are accessible

Correction
Here is what's right.

In Java, a multi-dimensional array is an array of arrays. We can access any of the arrays along the path towards the innermost elements:

int[][][] a;
// a refers to the outermost array of type int[][][]
a = new int[5][5][5]; // ok
// a[0] refers to one of the 5 subarrays of type int[][]
a[0] = new int[5][5]; // ok
// a[0][0] refers to one of the 5*5 subarrays of type int[]
a[0][0] = new int[5]; // ok
// a[0][0][0] refers to one of the 5*5*5 elements of type int
a[0][0][0] = 99; // ok (not surprising)

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.