Java EnumSet class

Java EnumSet class is the specialized Set implementation for use with enum types. It inherits AbstractSet class and implements the Set interface.

EnumSet class hierarchy

The hierarchy of EnumSet class is given in the figure given below.

EnumSet class hierarchy

EnumSet class declaration

Let's see the declaration for java.util.EnumSet class.

Methods of Java EnumSet class

Method Description
static > EnumSet allOf(Class elementType) It is used to create an enum set containing all of the elements in the specified element type.
static > EnumSet copyOf(Collection c) It is used to create an enum set initialized from the specified collection.
static > EnumSet noneOf(Class elementType) It is used to create an empty enum set with the specified element type.
static > EnumSet of(E e) It is used to create an enum set initially containing the specified element.
static > EnumSet range(E from, E to) It is used to create an enum set initially containing the specified elements.
EnumSet clone() It is used to return a copy of this set.

Java EnumSet Example

Output:

TUESDAY
WEDNESDAY

Java EnumSet Example: allOf() and noneOf()

Output:

Week Days:[SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY]
Week Days:[]
Next TopicJava EnumMap




Contact US

Email:[email protected]

Java EnumSet
10/30