English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java has many HashMap methods that allow us to use HashMap. On this reference page, you will find all available HashMap methods in Java, as well as usage examples of all HashMap methods. For example, if you need to add elements to the hashmap, you can use the put() method.
Method | Description |
---|---|
clear() | Remove all elements from HashMap |
clone() | Generate a copy of HashMap |
isEmpty() | Check if HashMap is empty |
size() | Return the number of items in HashMap |
put() | Insert the specified item into HashMap |
putAll() | Insert all items in the map into HashMap |
putIfAbsent() | If the key does not exist, insert the item |
remove() | Delete the mapping of the specified key |
containsKey() | Check if the specified key exists in the HashMap |
containsValue() | Check if the HashMap contains the specified value |
replace() | Replace the value of the specified key |
replaceAll() | Replace the value of all elements |
get() | Return the value using the specified key |
getOrDefault() | Return the specified default value if the key is not found |
forEach() | Perform an operation on all entries of the HashMap |
entrySet() | Return a set view of all entries |
keySet() | Return a set view of all keys in the HashMap |
values() | Return a view of all values existing in the HashMap |
merge() | Merge the specified mapping into the HashMaps |
compute() | Compute a new value for the specified key |
computeIfAbsent() | Compute a value if the mapping for the key does not exist |
computeIfPresent() | Compute a value for the map if the key exists |