Javatpoint Logo
Javatpoint Logo

Java EnumMap class

Java EnumMap class is the specialized Map implementation for enum keys. It inherits Enum and AbstractMap classes.

EnumMap class hierarchy

The hierarchy of EnumMap class is given in the figure given below.

EnumMap class hierarchy

EnumMap class declaration

Let's see the declaration for java.util.EnumMap class.

EnumMap class Parameters

Let's see the Parameters for java.util.EnumMap class.

  • K: It is the type of keys maintained by this map.
  • V: It is the type of mapped values.

Constructors of Java EnumMap class

Constructor Description
EnumMap(Class<K> keyType) It is used to create an empty enum map with the specified key type.
EnumMap(EnumMap<K,? extends V> m) It is used to create an enum map with the same key type as the specified enum map.
EnumMap(Map<K,? extends V> m) It is used to create an enum map initialized from the specified map.

Methods of Java EnumMap class

SN Method Description
1 clear() It is used to clear all the mapping from the map.
2 clone() It is used to copy the mapped value of one map to another map.
3 containsKey() It is used to check whether a specified key is present in this map or not.
4 containsValue() It is used to check whether one or more key is associated with a given value or not.
5 entrySet() It is used to create a set of elements contained in the EnumMap.
6 equals() It is used to compare two maps for equality.
7 get() It is used to get the mapped value of the specified key.
8 hashCode() It is used to get the hashcode value of the EnumMap.
9 keySet() It is used to get the set view of the keys contained in the map.
10 size() It is used to get the size of the EnumMap.
11 Values() It is used to create a collection view of the values contained in this map.
12 put() It is used to associate the given value with the given key in this EnumMap.
13 putAll() It is used to copy all the mappings from one EnumMap to a new EnumMap.
14 remove() It is used to remove the mapping for the given key from EnumMap if the given key is present.

Java EnumMap Example

Output:

Monday 1
Tuesday 2
Wednesday 3
Thursday 4

Java EnumMap Example: Book

Output:

101 Let us C Yashwant Kanetkar BPB 8
102 Data Communications & Networking Forouzan Mc Graw Hill 4
103 Operating System Galvin Wiley 6





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA