Java HashMap Methods
All HashMap Methods
A list of all HashMap methods can be found in the table below.
Some methods use the type of the HashMap's entries as a parameter or
return value. The type of the key will be referred to as K and the type of the
value will be referred to as V in the table.
Method Description Return Type
clear() Remove all entries from the map. void
clone() Create a copy of the HashMap. Object
compute() Compute a value for an entry based on V
its key and the current value (if it has
one)
computeIfAbs Compute a value for an entry based on V
ent() its key only if an entry using the key
does not already exist
computeIfPres Compute a new value for an entry based V
ent() on its key and current value but only if
an entry with the key already exists
containsKey() Indicate if an entry with the specified key boolean
exists in the map
containsValue Indicate if an entry with the specified boolean
() value exists in the map
entrySet() Return a set of all entries in the map Set<
[Link]<K,
V> >
forEach() Perform an action on every entry in the void
map
get() Return the value of the entry with a V
specified key
getOrDefault() Return the value of the entry with a V
specified key or a default value if the
entry is not found
isEmpty() Indicate whether the map is empty boolean
keySet() Return a set of all keys in the map Set<K>
merge() Compute a value for an entry based on V
its key and value or write a specific value
if the entry does not yet exist
put() Write an entry into the map V
putAll() Write all of the entries from another map void
into this one
putIfAbsent() Write an entry into the map but only if V
an entry with the same key does not
already exist
remove() Remove an entry from the map V|boolean
replace() Write to an entry in the map only if it V|boolean
exists
replaceAll() Replaces the value of every entry with void
the result of an operation
size() Return the number of entries in the map int
values() Return a collection containing all of the Collection<V>
values in the map
Related Pages
Java HashMap Tutorial