+ 1
Java multidimensional array with null value of second [ ]
if we create a multidimensional array like this: int[ ][ ] array = new int[2][ ]; what is this mean and can we initialize and use it?
2 odpowiedzi
+ 3
It means
int[][] array = {null, null};
+ 2
Hello Sheraz Tariq
It creates an array with 2 arrays in it.
Both arrays are null.
[null, null]
To initialize them:
array[0] = new array[size];
array[1] = new array[size];
size -> any length
For example:
array[0] = new int[3];
array[1] = new int[5];
[[0,0,0], [0,0,0,0,0]]
Btw: To print multidimensional arrays you can use Arrays:
import java.util.Arrays;
System.out.println(Arrays.deepToString(array));
(Array.toString() for one dimensional arrays)