MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

collections/SetOperations.java:8–29  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

6
7public class SetOperations {
8 public static void main(String[] args) {
9 Set<String> set1 = new HashSet<>();
10 Collections.addAll(set1,
11 "A B C D E F G H I J K L".split(" "));
12 set1.add("M");
13 System.out.println("H: " + set1.contains("H"));
14 System.out.println("N: " + set1.contains("N"));
15 Set<String> set2 = new HashSet<>();
16 Collections.addAll(set2, "H I J K L".split(" "));
17 System.out.println(
18 "set2 in set1: " + set1.containsAll(set2));
19 set1.remove("H");
20 System.out.println("set1: " + set1);
21 System.out.println(
22 "set2 in set1: " + set1.containsAll(set2));
23 set1.removeAll(set2);
24 System.out.println(
25 "set2 removed from set1: " + set1);
26 Collections.addAll(set1, "X Y Z".split(" "));
27 System.out.println(
28 "'X Y Z' added to set1: " + set1);
29 }
30}
31/* Output:
32H: true

Callers

nothing calls this directly

Calls 5

addAllMethod · 0.80
splitMethod · 0.80
containsMethod · 0.80
addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected