🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
    }
}
  1. A.[3, 1, 2]
  2. B.[3, 1]
  3. C.[1, 2]
  4. 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 →