'How do you check if the Second Dimension of a 2D array is null?
Lets say for example you have a 2D Array field[60][]
.
How exactly can you check if the second part of the Array is null?
Is there any way to do something similiar like if(field ==null)
but for the second dimension?
Solution 1:[1]
Just for illustration purpose:
Integer field[][]=new Integer[2][];
field[0]=new Integer[2]; //you can declare size for second dimension like this.
if(field[0]==null) { // do null checks
System.out.println("field[0] is null");
}if(field[1]==null) {
System.out.println("field[1] is null");
}
Output:
field[1] is null
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ashish Patil |