![]() |
VOOZH | about |
EnumMap and EnumSet both are the classes defined inside the java collection. In this article, we will learn the differences between EnumMap and EnumSet. EnumMap is the specialized implementation of the Map interface and the EnumSet is the specialized implementation of the Set interface. There are some differences that exist between them. So we have tried to list out the differences between EnumMap and EnumSet.
1. EnumMap: EnumMap is a specialized implementation of the Map interface for enumeration types. It implements the Map interface and extends AbstractMap in Java.
Below is the implementation of the EnumMap:
Size of EnumMap: 4 Apple 1 Mango 2 Orange 3 Banana 4
2. EnumSet: EnumSet is a specialized implementation of the Set interface for enumeration types. It implements the Set interface and extends AbstractSet in Java.
Below is the implementation of the EnumSet:
EnumSet : Monday Tuesday
| EnumMap | EnumSet |
|---|---|
| EnumMap is a specialized implementation of the Map interface for the enumeration types. | EnumSet is a specialized implementation of the Set interface for the enumeration types. |
| EnumMap is internally represented as an array. | EnumSet is internally represented as a BitVector. |
| EnumMap doesn't allow to insert the null keys, however, null values can be inserted. | EnumSet doesn't allow inserting null elements. |
| EnumMap is not an abstract class. | EnumSet is an abstract class. |
| EnumMap is not an abstract class therefore, we can create an instance of this class. | EnumSet is an abstract class therefore, we can not create the instance of this class. |