Java EnumMap Class Methods

The EnumMap class in Java is a specialized Map implementation designed for use with enum types. It is a high-performance Map implementation for use with enum keys, which makes it faster than other Map implementations. The EnumMap maintains all of the elements in a specific order (the natural order of the enum keys).

This guide covers various methods available in the EnumMap class, offering a comprehensive understanding of how to manipulate and interact with enum maps in Java. These methods are essential for efficient coding practices and help in performing operations like adding, removing, and checking for key-value pairs.

For more detailed information, you can refer to the official Java SE Documentation and additional resources on Java Collections Tutorial.

EnumMap Class Methods

Method Description
put() Adds a key-value pair to the EnumMap.
get() Retrieves the value associated with a specific key.
containsKey() Checks if the EnumMap contains a specific key.
containsValue() Checks if the EnumMap contains a specific value.
size() Returns the number of key-value pairs in the EnumMap.
isEmpty() Checks if the EnumMap is empty.
keySet() Returns a set view of the keys contained in the EnumMap.
values() Returns a collection view of the values contained in the EnumMap.
entrySet() Returns a set view of the key-value pairs in the EnumMap.
forEach() Performs the given action for each key-value pair in the EnumMap.
getOrDefault() Returns the value for a key, or a default value if the key is not found.
putIfAbsent() Adds a key-value pair if the key is not already present in the EnumMap.
remove() Removes the key-value pair for a specific key.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top