Java Collections Java Java API
Class:
java.util.EnumSet
Methods:
Creates an enum set initially containing the specified element. Overloadings of this method exist to initialize an
enum set with one through five elements. A sixth overloading is provided that uses the varargs feature. This
overloading may be used to create an enum set initially containing an arbitrary number of elements, but is likely to
run slower than the overloadings that do not use varargs.
public static <E extends Enum<E>> EnumSet<E> of(E e)
public static <E extends Enum<E>> EnumSet<E> of(E e1,
E e2)
public static <E extends Enum<E>> EnumSet<E> of(E e1,
E e2,
E e3)
public static <E extends Enum<E>> EnumSet<E> of(E e1,
E e2,
E e3,
E e4)
public static <E extends Enum<E>> EnumSet<E> of(E e1,
E e2,
E e3,
E e4,
E e5)
@SafeVarargs
public static <E extends Enum<E>> EnumSet<E> of(E first,
E... rest)
Examples
package com.logicbig.example.enumset;
import java.time.Month; import java.util.EnumSet;
public class OfExample {
public static void main(String... args) { EnumSet<Month> set = EnumSet.of(Month.JANUARY, Month.JULY); System.out.println(set); } }
Output[JANUARY, JULY]
|