🎙 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 4 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(10, 20, 30));
        l.remove(1);
        System.out.println(l);
    }
}
  1. A.[20, 30]
  2. B.[10, 30]
  3. C.[10, 20, 30]
  4. D.[10, 20]
Answer & explanation

Correct answer: [10, 30]

remove(1) with an int removes the element at index 1, which is 20.

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 →