I am struggling with EnumSet as it surprisingly doesn't have a simple constructor and its methods doesn't like null values.
What I came up with: EnumSet<MyClass> x = EnumSet.copyOf(Collections.<MyClass>emptySet());
Which somewhat works but doesn't seem right to me.
An enumSet is a Java Collections member, it is not synchronized. An enumSet is a high performing set implementation that works faster than the HashSet. All the elements in an enumSet must be of a single enumeration type that is specified when the set is created.
Yes EnumSet is modifiable. If you want to create an immutable EnumSet then go for immutableEnumSet. Returns an immutable set instance containing the given enum elements. Internally, the returned set will be backed by an EnumSet .
Use EnumSet. noneOf(Class) to create an empty EnumSet.
The EnumSet is one of the specialized implementations of the Set interface for use with the enumeration type. A few important features of EnumSet are as follows: It extends AbstractSet class and implements Set Interface in Java. EnumSet class is a member of the Java Collections Framework & is not synchronized.
Use the method EnumSet.noneOf
:
EnumSet<MyClass> x = EnumSet.noneOf(MyClass.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With