Three Dimensional Arrays in Java

In this class, We discuss Three Dimensional Arrays in Java.

The reader should have prior knowledge of two-dimensional arrays. Click Here.

The below statement shows the declaration of a three-dimensional array.

int[][][] a = new int[3][2][5];

The above three-dimensional array has three 2X5 two-dimensional arrays.

The below diagram shows a three-dimensional array.

The first two-dimensional array is given index zero.

The second two-dimensional array is given index one. And so on.

To access the element present in the position a[0][1][2].

The zero shows the first two-dimensional array.

The one shows line one in a two-dimensional array.

The two show the second column in a two-dimensional array.

The element at position a[0][1][2] is 8.

The below diagram shows the three-dimensional array in random access memory.

The first array has three positions to store the address of three two-dimensional arrays.

The second-level arrays have two positions to point to two arrays because each two-dimensional array has two lines.

The below diagram shows the program to declare a variable-length three-dimensional array.

We use a three-level nested loop to access the elements in the three-dimensional array.

We use the length attribute to find the variable length arrays.