Skip to content
Sharp

Collections · interview question

What does this print?

What does this code output?Medium
java
public class Main {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>(List.of(1, 2, 3));
        list.remove(1);
        System.out.println(list);
    }
}
Choose one answer
Answer and explanation

Correct answer

A. [1, 3]

Why

remove(1) matches the overload remove(int index) (an exact primitive match beats boxing), so it removes the element at index 1, which is the value 2.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →