What is the output of the Java code List<Integer> x = new ArrayList<>(List.of(10, 20, 30)); x.remove(1); System.out.println(x);?
Correct answer A. [10, 30]
Explanation
List has both remove(int index) and remove(Object o). The argument 1 is an int, so overload resolution chooses remove(int) without any boxing, and the element at index 1, which is 20, is removed. Passing Integer.valueOf(1) would select remove(Object), find no match and leave the list unchanged.
Answer checked How we write and check questions
Discussion