← 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);
}
}
- A.[20, 30]
- B.[10, 30]
- C.[10, 20, 30]
- 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 →