Yandex

Java Advanced ConceptsJava Advanced Concepts3

Java HashMap Methods Reference



clear()
public void clear()
Removes all mappings from the map.
clone()
public Object clone()
Returns a shallow copy of the HashMap.
compute()
public V compute(K key, BiFunction remappingFunction)
Attempts to compute a new mapping for the specified key.
computeIfAbsent()
public V computeIfAbsent(K key, Function mappingFunction)
Computes and stores a value for the key if it is not already present.
computeIfPresent()
public V computeIfPresent(K key, BiFunction remappingFunction)
Updates the value only if the key is already present.
containsKey()
public boolean containsKey(Object key)
Checks if the map contains the specified key.
containsValue()
public boolean containsValue(Object value)
Checks if the map maps one or more keys to the specified value.
entrySet()
public Set> entrySet()
Returns a set view of the key-value mappings.
forEach()
public void forEach(BiConsumer action)
Performs an action for each entry in the map.
get()
public V get(Object key)
Returns the value to which the specified key is mapped, or null.
getOrDefault()
public V getOrDefault(Object key, V defaultValue)
Returns the value for the key, or a default if the key is not present.
isEmpty()
public boolean isEmpty()
Checks if the map contains no key-value mappings.
keySet()
public Set keySet()
Returns a Set view of the keys contained in the map.
merge()
public V merge(K key, V value, BiFunction remappingFunction)
Merges the value with existing value using a mapping function.
put()
public V put(K key, V value)
Associates the specified value with the specified key in the map.
putAll()
public void putAll(Map m)
Copies all of the mappings from the specified map to this map.
putIfAbsent()
public V putIfAbsent(K key, V value)
Puts the value only if the key is not already associated with a value.
remove()
public V remove(Object key)public boolean remove(Object key, Object value)
Removes the mapping for the specified key or key-value pair.
replace()
public V replace(K key, V value)public boolean replace(K key, V oldValue, V newValue)
Replaces the entry for the specified key if it is currently mapped.
replaceAll()
public void replaceAll(BiFunction function)
Replaces each entry’s value using the provided function.
size()
public int size()
Returns the number of key-value mappings in the map.
values()
public Collection values()
Returns a Collection view of the values contained in the map.


Welcome to ProgramGuru

Sign up to start your journey with us

Support ProgramGuru.org

You can support this website with a contribution of your choice.

When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.

PayPal

UPI

PhonePe QR

MALLIKARJUNA M