Summary

This lesson lists the important interfaces and classes of the Collections Framework.

We'll cover the following...
Set
EnumSet

An EnumSet is a specialized Set collection to work with enum classes. EnumSet should always be preferred over any other Set implementation when we are storing enum values. All of the elements in an enum set must come from a single enum type that is specified, explicitly or implicitly, when the set is created. Enum sets are represented internally as bit vectors.

EnumSet is a public abstract class that contains multiple static factory methods that allow us to create instances. There are two implementations:

  • RegularEnumSet: Uses a single long to represent the bit vector. Each bit of the long element represents a value of the enum. The i-th value of the enum will be stored in the i-th bit. Can store up to 64 elements.
  • JumboEnumSet: Uses an array of long elements as a bit vector. Can store more than 64 elements. Works like RegularEnumSet but with extra calculations for the array index.

EnumSet<DayOfWeek> myEnumSet = EnumSet.allOf(DayOfWeek.class);
System.out.println(myEnum
...