If you create an array of scalar types such as int, initialize the elements to zero.
On the other hand, created an array with the reference type, factors such as integer null to reset.
You can check if it is 0 or null.
jshell> int[][] array = new int[3][3]
array ==> int[3][] { int[3] { 0, 0, 0 }, int[3] { 0, 0, 0 }, int[3] { 0, 0, 0 } }
jshell> array[1][2]
$2 ==> 0
jshell> array[1][2] != 0
$3 ==> false
jshell> Integer[][] array2 = new Integer[3][3]
array2 ==> Integer[3][] { Integer[3] { null, null, null }, I ... [3] [3] { null, null, null } }
jshell> array2[1][2]
$5 ==> null
jshell> array2[1][2] != null
$6 ==> false
© 2024 OneMinuteCode. All rights reserved.