bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java HashMap Methods

Flash cards

Review the key moves

1/3
Core idea

What is the main idea behind Java HashMap Methods?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Order

Put the learning moves in the order that makes the concept easiest to apply.

Some methods use the type of the HashMap's entries as a parameter or return value.
A list of all HashMap methods can be found in the table below.
All 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.

MethodDescriptionReturn 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 its key and the current value (if it has one)V
computeIfAbsent()Compute a value for an entry based on its key only if an entry using the key does not already existV
computeIfPresent()Compute a new value for an entry based on its key and current value but only if an entry with the key already existsV
containsKey()Indicate if an entry with the specified key exists in the mapboolean
containsValue()Indicate if an entry with the specified value exists in the mapboolean
entrySet()Return a set of all entries in the mapSet< Map.Entry<K,V> >
forEach()Perform an action on every entry in the mapvoid
get()Return the value of the entry with a specified keyV
getOrDefault()Return the value of the entry with a specified key or a default value if the entry is not foundV
isEmpty()Indicate whether the map is emptyboolean
keySet()Return a set of all keys in the mapSet< K >
merge()Compute a value for an entry based on its key and value or write a specific value if the entry does not yet existV
put()Write an entry into the mapV
putAll()Write all of the entries from another map into this onevoid
putIfAbsent()Write an entry into the map but only if an entry with the same key does not already existV
remove()Remove an entry from the mapVboolean
replace()Write to an entry in the map only if it existsVboolean
replaceAll()Replaces the value of every entry with the result of an operationvoid
size()Return the number of entries in the mapint
values()Return a collection containing all of the values in the mapCollection< V >

Previous

Java LinkedList toArray() Method

Next

Java HashMap clear() Method