EnumMap is optimized Map implementation exclusively for enum keys
1. All keys used in EnumMap must be from same Enum type which is specified while creating EnumMap in Java. For example if you can not use different enum instances from two different enum.
2. EnumMap is ordered collection and they are maintained in the natural order of their keys( natural order of keys means the order on which enum constant are declared inside enum type ). you can verify this while Iterating over an EnumMap in Java.
3. Iterators of EnumMap are fail-fast Iterator , much like of ConcurrentHashMap and doesn't throw ConcurrentModificationException and may not show effect of any modification on EnumMap during Iteration process.
4. You can not insert null keys inside EnumMap in Java. EnumMap doesn't allow null key and throw NullPointerException, at same time null values are permitted.
5. EnumMap is not synchronized and it has to be synchronized manually before using it in a concurrent or multi-threaded environment. like synchronized Map in Java you can also make EnumMap synchronized by using Collections.synchronizedMap() method and as per javadoc this should be done while creating EnumMap in java to avoid accidental non synchronized access.
6. EnumMap is likely give better performance than HashMap in Java. So prefer EnumMap if you are going to use enum keys.
Read full article from What is EnumMap in Java – Example Tutorial
1. All keys used in EnumMap must be from same Enum type which is specified while creating EnumMap in Java. For example if you can not use different enum instances from two different enum.
2. EnumMap is ordered collection and they are maintained in the natural order of their keys( natural order of keys means the order on which enum constant are declared inside enum type ). you can verify this while Iterating over an EnumMap in Java.
3. Iterators of EnumMap are fail-fast Iterator , much like of ConcurrentHashMap and doesn't throw ConcurrentModificationException and may not show effect of any modification on EnumMap during Iteration process.
4. You can not insert null keys inside EnumMap in Java. EnumMap doesn't allow null key and throw NullPointerException, at same time null values are permitted.
5. EnumMap is not synchronized and it has to be synchronized manually before using it in a concurrent or multi-threaded environment. like synchronized Map in Java you can also make EnumMap synchronized by using Collections.synchronizedMap() method and as per javadoc this should be done while creating EnumMap in java to avoid accidental non synchronized access.
6. EnumMap is likely give better performance than HashMap in Java. So prefer EnumMap if you are going to use enum keys.
Read full article from What is EnumMap in Java – Example Tutorial
No comments:
Post a Comment