set3.add(“Savanna”);
set3.add(“Atlanta”);
System.out.println(set1.equals(set2) + ” ” + set1.equals(set3));
}
}
a. true true
b. true false
c. false false
d. false true
#
Section 21.2.2 LinkedHashSet
4. What is the output of the following code?
import java.util.*;
public class TestLinkedHashSet {
public static void main(String[] args) {
// Create a linked hash set
Set<String> set = new LinkedHashSet<>();
// Add strings to the set
set.add(“London”);
set.add(“Paris”);
set.add(“New York”);
set.add(“San Francisco”);
set.add(“Beijing”);
set.add(“New York”);
System.out.println(set);
}
}
a. [“London”, “Paris”, “New York”, “San Francisco”, “Beijing”]
b. [London, Paris, New York, San Francisco, Beijing]
c. [“London”, “Paris”, “New York”, “San Francisco”, “Beijing”, “New York”]
d. [London, Paris, New York, San Francisco, Beijing, New York]
#
15. The output of the following code is .
LinkedHashSet<String> set1 = new LinkedHashSet<>();
set1.add(“New York”);
LinkedHashSet<String> set2 = (LinkedHashSet<String>)(set1.clone());
set1.add(“Atlanta”);
set2.add(“Dallas”);
System.out.println(set2);
a. [New York]
b. [New York, Atlanta]
c. [New York, Atlanta, Dallas]
d. [New York, Dallas]