EnumMap
Let's discuss the working of EnumMap.
The EnumMap is a special kind of Map in which the keys are only of the Enum type. Although it is possible to use the Enum type as a key in other Map implementations such as a HashMap or TreeMap, but a separate Map implementation was created for performance reasons.
The EnumMap is highly efficient, and we will discuss more when we will look at how it works internally. Let’s look at some of the features of EnumMap.
- EnumMap does not allow null keys, but it allows null values.
- The keys are stored in their natural order. In the case of an Enum, the natural order of keys means the order where enum constant is declared inside Enum type.
- The EnumMap is not synchronized.
- All keys of each EnumMap instance must be keys of a single Enum type.