Java EnumSet.range(E from, E to)

Syntax

EnumSet.range(E from, E to) has the following syntax.

public static <E extends Enum <E>> EnumSet <E> range(E from,     E to)

Example

In the following code shows how to use EnumSet.range(E from, E to) method.


//  ww w  . j  a v a  2 s.  c  o  m


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 one element
      set = EnumSet.range(Numbers.TWO, Numbers.FIVE);


      System.out.println(set);

   }
}

The code above generates the following result.