EnumMap class Methods in Java

java.util.EnumMap<K, V>

A specialized Map implementation for use with enum type keys. All of the keys in an enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is created.

Note: All basic operations execute in constant time.


Some methods of EnumMap class.


clear(): This method removes all mappings from this map.


clone(): This method returns a shallow copy of this enum map.


compute(K, V): This method Attempts to compute a mapping for the specified key and its current mapped value.


computeIfAbsent(K, Function): If the specified key is not already associated with a value attempt to compute its value using the given mappingfunction and enter it into this map unless null.


computeIfPresent(K, BiFunction): If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.


containsKey(Object): This method returns true if this map contains a mapping for the specified key.


containsValue(Object): This method returns true if this map maps one or more keys to the specified value.


entrySet(): This method returns a Set view of the mappings contained in this map.


equals(Object): This method compares the specified object with this map for equality.


forEach(BiConsumer): This method performs the given action for each entry in this map until all entries have been processed or the action throws an exception.


get(Object): This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.


getOrDefault(Object, V): This method returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.


hashCode(): This method returns the hash code value for this map. 


isEmpty(): This method returns true if this map contains no key-value mappings.


keySet(): This method returns a Set view of the keys contained in this map.


merge(K, V, BiFunction): If the specified key is not already associated with a value or is associated with null, associate it with the given non-null value.


put(K, V):  This method associates the specified value with the specified key in this map.


putAll(Map): This method copies all of the mappings from the specified map to this map.


remove(Object): This method removes the mapping for this key from this map if present.


remove(Object, Object): This method removes the entry for the specified key only if it is currently mapped to the specified value.


replace(K, V): This method replaces the entry for the specified key only if it is currently mapped to some value.


replace(K, V, V): This method replaces the entry for the specified key only if currently mapped to the specified value.


replaceAll(BiFunction): This method replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.


size(): This method returns the number of key-value mappings in this map.


toString(): This method returns a string representation of this map.


values(): This method returns a Collection view of the values contained in this map.


No comments:

Post a Comment