← Quiz: Java Collections (List and Set): all 10 questions
Quiz: Java Collections (List and Set) · Question 10 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
List<Integer> l = new ArrayList<>(List.of(3, 1, 2));
l.remove(Integer.valueOf(1));
System.out.println(l);
}
}
- A.[3, 1, 2]
- B.[3, 1]
- C.[1, 2]
- D.[3, 2]
Answer & explanation
Correct answer: [3, 2]
Integer.valueOf(1) is an object, so remove(Object) deletes the value 1. remove(1) with a plain int would delete index 1 instead.
Can you get the rest right without peeking?
Take the timed Quiz: Java Collections (List and Set) quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →