java tutorial - Java EnumMap class - java programming - learn java - java basics - java for beginners
Learn Java - Java tutorial - Java enummap - Java examples - Java programs
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.
Learn java - java tutorial - enummap - java examples - java programs
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
Method | Description |
---|---|
void clear() | It is used to remove all mappings from this map. |
boolean containsKey(Object key) | This method return true if this map contains a mapping for the specified key. |
boolean containsValue(Object value) | This method return true if this map maps one or more keys to the specified value. |
boolean equals(Object o) | It is used to compare the specified object with this map for equality. |
V get(Object key) | This method returns the value to which the specified key is mapped. |
V put(K key, V value) | It is used to associate the specified value with the specified key in this map. |
V remove(Object key) | It is used to remove the mapping for this key. |
Collection<V> values() | It is used to return a Collection view of the values contained in this map. |
int size() | It is used to return the number of key-value mappings in this map. |