Java HashMap Methods

Java has a lot of HashMap methods that allow us to work with hashmaps. In this reference page, you will find all the hashmap methods available in Java. For example, if you need to add an element to the hashmap, use the put() method.

Java HashMap clear()

remove all elements from HashMap

Java HashMap clone()

makes the copy of the hashmap

Java HashMap isEmpty()

checks if the HashMap is empty

Java HashMap size()

returns the number of items in HashMap

Java HashMap put()

inserts the specified item to the hashmap

Java HashMap putAll()

inserts all items from a map to HashMap

Java HashMap putIfAbsent()

inserts item if the key is not already present

Java HashMap remove()

removes the mapping for the specified key

Java HashMap containsKey()

checks if the specified key is present in HashMap

Java HashMap containsValue()

checks if HashMap contains the specified value

Java HashMap replace()

replaces the value for the specified key

Java HashMap replaceAll()

replaces all values with

Java HashMap get()

returns the value using the specified key

Java HashMap getOrDefault()

returns specified default value if key not found

Java HashMap forEach()

performs the action to all entries of HashMap

Java HashMap entrySet()

returns a set view of all entries

Java HashMap keySet()

returns a set view of all the keys of HashMap

Java HashMap values()

returns a view of all values present in HashMap

Java HashMap merge()

merges the specified mapping to the HashMaps

Java HashMap compute()

computes a new value for the specified key

Java HashMap computeIfAbsent()

computes value if mapping for key is not present

Java HashMap computeIfPresent()

computes a value for the mapping if key is present