I have a Java int[][][] object in a separate class.
The first dimension of the array has about 1000 elements, but I only need to access one at a time.
My question is: If I want to access only one element at a time, like this:
int[][] some2DInt = SomeClass.some3DInt[5];
Would this be effective? I mean, would Java load the entire 1000 elements or just the one I really want?
There is no loading here.
int[][]is an address so when you do something like :You just assign to
some2DIntthe address of the fifth 2 dimensional array in memory. So no copying or “loading” is done.The loading (which is actually memory allocation) is done when you initialize your 3 dimensional array using the
newoperator. (or if you statically initialize this array which might be a cumbersome task especially with 1000 2d arrays)