Checking for Null in an Array
Which of the following conditions correctly checks that names[2] is not null?
public class ObjectArrayCheck {
public static void main(String[] args) {
String[] names = new String[3];
names[0] = "Alice";
names[1] = "Bob";
// Missing line: Check whether names[2] is not null before attempting to print its length.
if (names[2] != null) {
System.out.println(names[2].length());
}
}
}
A
if (names[2] != null)
B
if (names[2] == null)
C
if (names[2].equals(null))
D
if (names[2].length() > 0)
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | y.seong2027 | 1 | 1 | 0m 06s | 94 |
| #2 | sailajavadlamani33 | 1 | 1 | 1m 03s | 37 |
| #3 | bommasam000 | 2 | 5 | 2m 18s | 32 |
| #4 | sssemihunal | 0 | 1 | 0m 01s | -11 |
Items per page:
10
1 – 4 of 4
APFIVE