
Set Containers 325
HashSet, 317 Set algebraic operations, 318 TreeSet, 317
LinkedHashSet, 317 Set interface, 317
Multiple-choice Questions
1. What is the output?
HashSet set = new HashSet();
set.add(1);
set.add(2);
set.add(1);
System.out.println(set);
a. [1,2,1] b. [1,2]
c. [1] d. IllegalArgumentException
2. What is the output?
HashSet set1 = new HashSet();
set1.add(1);
set1.add(2);
set1.add(1);
HashSet set2 = new HashSet();
set2.add(4);
set2.add(3);
set1.addAll(set2);
System.out.println(set1);
a. [1,2,3,4] b. [1,2,1,4,3]
c. [1,2,4,3] d. [2,1,4,3]
3. What is the output?
HashSet set1 = new HashSet();
set1.add(1);
set1.add(3);
REVIEW QUESTIONS
KEY TERMS ...