介绍
java.util.EnumSet
public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> implements Cloneable, java.io.Serializable
API
static
- of
- noneOf
- allOf
- range
- copyOf
- complementOf
public
示例代码
public class TestEnumSet {
@Test
public void test1() {
EnumSet<MyEnum> enumSet = EnumSet.of(MyEnum.ONE, MyEnum.THREE);
EnumSet<MyEnum> clone = enumSet.clone();
System.out.println(enumSet == clone); // false
System.out.println(enumSet.equals(clone)); // true
EnumSet<MyEnum> range = EnumSet.range(MyEnum.ONE, MyEnum.FOUR);
System.out.println(range); // [ONE, TWO, THREE, FOUR]
EnumSet<MyEnum> complement = EnumSet.complementOf(range);
System.out.println(complement); // [FIVE]
}
}
enum MyEnum {
ONE, TWO, THREE, FOUR, FIVE
}