← Quiz: Java Collections (List and Set): all 10 questions
Quiz: Java Collections (List and Set) · Question 1 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 HashSet<>(List.of("a", "b"));
s.add("a");
s.add("c");
System.out.println(s.size());
}
}
- A.4
- B.3
- C.2
- D.Error
Answer & explanation
Correct answer: 3
"a" is already present, so only "c" is added: a, b, c.
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 →