java.util · java.base · since Java 1.5

EnumSet

declaration
public abstract class EnumSet<E extends Enum<E>>
        extends AbstractSet<E> implements Cloneable, Serializable

Set of enum constants backed by a bit vector (one long for ≤64 constants): bit-mask performance with type-safe Set semantics. The replacement for int flag fields (EJ 36).

Key methods

static <E> EnumSet<E> of(E first, E... rest)Literal sets.
static <E> EnumSet<E> allOf/noneOf(Class<E>)Full / empty sets.
static <E> EnumSet<E> range(E from, E to)Contiguous run of declared constants, both endpoints inclusive.
static <E> EnumSet<E> complementOf(EnumSet<E>)Set inversion.
static <E> EnumSet<E> copyOf(Collection<E>)Defensive copy — the source must be an EnumSet or a non-empty collection (to infer the element type).