enum Color { RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET } EnumSetrainbow = EnumSet.range(Color.RED, Color.BLUE); System.out.println(rainbow);
[RED, ORANGE, YELLOW, GREEN, BLUE]In conclusion, the EnumSet is a package in the Java library that provides specialized Set implementation optimized for the use of enum types. The range() method is one of the methods provided by EnumSet that creates a subset of the Set containing all of the elements within the specified range.