← Quiz: Java Collections (List and Set): all 10 questions
Quiz: Java Collections (List and Set) · Question 7 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
Set<String> s = new LinkedHashSet<>(List.of("pune", "agra", "pune", "delhi"));
System.out.println(s);
}
}
- A.[pune, agra, delhi]
- B.[agra, delhi, pune]
- C.[pune, agra, pune, delhi]
- D.[delhi, agra, pune]
Answer & explanation
Correct answer: [pune, agra, delhi]
LinkedHashSet removes the duplicate and keeps the order in which elements were first added.
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 →