Java Collection Tutorial - Java EnumSet.of(E e1, E e2, E e3)








Syntax

EnumSet.of(E e1, E e2, E e3) has the following syntax.

public static <E extends Enum <E>> EnumSet <E> of(E e1,    E e2,    E e3)

Example

In the following code shows how to use EnumSet.of(E e1, E e2, E e3) method.

/*w  w  w. ja  v  a 2  s.  com*/


import java.util.EnumSet;
   
enum Numbers {

   ONE, TWO, THREE, FOUR, FIVE
};
public class Main {

   public static void main(String[] args) {

      // create a set
      EnumSet<Numbers>  set;

      // add elements
      set = EnumSet.of(Numbers.FIVE,Numbers.FOUR,Numbers.THREE);

      System.out.println(set);

   }
}

The code above generates the following result.