+ 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?

26th Apr 2020, 7:54 PM
Sheraz Tariq
Sheraz Tariq - avatar
2 Respostas
+ 3
It means int[][] array = {null, null};
26th Apr 2020, 8:36 PM
Alisa Samosudova
Alisa Samosudova - avatar
+ 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)
27th Apr 2020, 1:14 AM
Denise Roßberg
Denise Roßberg - avatar