Which of the following are true statements about the following code?
Choose all that apply
4: List<Integer> v = new ArrayList<>(); 5: v.add(Integer.parseInt("5")); 6: v.add(Integer.valueOf("6")); 7: v.add(7); 8: v.add(null); 9: for (int age : v) System.out.print(age);
A, B, D.
Lines 5 and 7 use autoboxing to convert an int to an Integer.
Line 6 does not because valueOf()
returns an Integer.
Line 8 does not because null is not an int.
The code does not compile.
However, when the for loop tries to unbox null into an int, it fails and throws a NullPointerException.