Laky - 7 months ago 38

Java Question

I am new to Java and I saw a video about 2D arrays online. But what about 3D arrays?

Is it possible to make a 3D array in Java? If so, how can this be done. Also, would using 3 separate 1D arrays (that are linked together) be equivalent to using 1 3D array? Finally, what is the efficiency of traversing through a 3D array?

Answer

Making a 3D array is quite possible in Java. It's as simple as declaring the type `T[][][] array;`

. Three separate 1D arrays are not equivalent to one 3D array. You would need `n`

2D arrays to be equivalent to one 3D array. The efficiency of traversing a 3D array is practically O(n³).