🎙 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 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);
    }
}
  1. A.[pune, agra, delhi]
  2. B.[agra, delhi, pune]
  3. C.[pune, agra, pune, delhi]
  4. 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 →