-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetOperations.java
More file actions
28 lines (23 loc) · 813 Bytes
/
SetOperations.java
File metadata and controls
28 lines (23 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package chapter11;
import java.util.*;
import net.mindview.util.Print;
import static net.mindview.util.Print.*;
public class SetOperations {
public static void main(String[] args) {
Set<String> set1 = new HashSet<String>();
Collections.addAll(set1, "A B C D E F G H I J K L".split(" "));
set1.add("M");
print("H: "+set1.contains("H"));
print("N: "+set1.contains("N"));
Set<String> set2 = new HashSet<String>();
Collections.addAll(set2, "H I J K L".split(" "));
print("set2 in set1: "+set1.containsAll(set2));
set1.remove("H");
print("set1: "+set1);
print("set2 in set1: "+set1.containsAll(set2));
set1.removeAll(set2);
print("set2 removed from set1: "+set1);
Collections.addAll(set1, "X Y Z".split(" "));
print("'X Y Z' added to set1: "+set1);
}
}