EnumSet : Java Glossary


EnumSet lets you handle combinations of enum constants. If you are a mathematician, you might look on EnumSet as a way of doing efficient set operations such as union, intersection, difference and complement. Internally the calculations are done with bits, packed into longs, much like BitSet. This representation is compact and efficient. If you study the documentation for EnumSet you will not see much. EnumSet inherits all its useful methods from AbstractCollection via AbstractSet.

If you are a programmer, you might look on EnumSet as a high level way of manipulating bit flags and bit masks.

Note it is spelled EnumSet not Enumset.

Using An EnumSet

Here is a little program to demonstrate some of the things you can do with an EnumSet.

Two other techniques for dealing with sets include HashSet and BitSet. You can also do low level bit masking using byte, int or long.

You would think there would be methods corresponding to the things mathematicians do with sets, but they are not implemented. e.g. union, intersection, subtract, isSubsetOf, isSupersetOf… There is Interface.containsAll Set.retainAll, but not very efficiently implemented.

Learning More

Oracle’s Javadoc on EnumSet class : available:
Oracle’s Javadoc on AbstractCollection class : available:
Oracle’s Javadoc on Set class : available:
Oracle’s Javadoc on Collections.unmodifiableSet : available:

This page is posted
on the web at:


Optional Replicator mirror
of mindprod.com
on local hard disk J:

Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number