With the following Java examples:
int[] array1 = new int[]; // Incorrect, since no size is given
int[] array2 = new int[2]; // Correct
int[][][] array3 = new int[][][]; // Incorrect, since no size is given
int[][][] array4 = new int[2][2][2]; // Correct
int[][][] array5 = new int[2][][]; // Correct (why is this correct?)
So, my question is, why is assigning only the first size of a multidimensional array sufficient enough? I thought you always had to assign a size, even to each individual array-part of a multidimensional array, but today I found out that array5 is also a correct way for Java. Now I'm just wondering why. Can someone give some examples of why this works for multidimensional arrays and/or the reasoning behind it?
Also, I guess that the following applies as well then:
int[][][] array6 = new int[][2][]; // Incorrect
int[][][] array7 = new int[][][2]; // Incorrect
int[][][] array8 = new int[][2][2]; // Incorrect
int[][][] array9 = new int[2][2][]; // Correct
int[][][] array10 = new int[2][][2]; // Incorrect?? (Or is this correct?)
I'm a bit puzzled now and would like some clarification if someone knows it.
EDIT / SEMI-SOLUTION:
Ok, I found out why the first part works:
int[][] array = new int[2][];
array[0] = new int[5];
array[1] = new int[3];
// So now I have an array with the following options within the array-index bounds:
// [0][0]; [0][1]; [0][2]; [0][3]; [0][4]; [1][0]; [1][1]; [1][2]
// It basically means I can have different sized inner arrays
The only thing left to answer is if:
int[][][] array10 = new int[2][][2]; // Incorrect?? (Or is this correct?)
is valid or not.