-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEnumSets.java
More file actions
40 lines (30 loc) · 1.07 KB
/
EnumSets.java
File metadata and controls
40 lines (30 loc) · 1.07 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
package enumerated;
import java.util.*;
import static enumerated.AlarmPoints.*;
/**
* RUN:
* javac enumerated/EnumSets.java && java enumerated.EnumSets
* OUTPUT:
* [BATHROOM]
* [STAIR1, STAIR2, BATHROOM, KITCHEN]
* [LOBBY, OFFICE1, OFFICE2, OFFICE3, OFFICE4, BATHROOM, UTILITY]
* [LOBBY, OFFICE2, OFFICE3, BATHROOM, UTILITY]
* [STAIR1, STAIR2, OFFICE1, OFFICE4, KITCHEN]
*/
public class EnumSets {
public static void main(String[] args) {
// empty set
EnumSet<AlarmPoints> points = EnumSet.noneOf(AlarmPoints.class);
points.add(BATHROOM);
System.out.println(points);
points.addAll(EnumSet.of(STAIR1, STAIR2, KITCHEN));
System.out.println(points);
points = EnumSet.allOf(AlarmPoints.class);
points.removeAll(EnumSet.of(STAIR1, STAIR2, KITCHEN));
System.out.println(points);
points.removeAll(EnumSet.of(OFFICE1, OFFICE4));
System.out.println(points);
points = EnumSet.complementOf(points);
System.out.println(points);
}
}