Home » Java ConcurrentHashMap remove() Method

Java ConcurrentHashMap remove() Method

by Online Tutorials Library

Java ConcurrentHashMap remove() Method

The remove() method of ConcurrentHashMap class removes the key (and its corresponding value) from this map. This method does nothing if the key is not on the map.

Syntax

Parameter

key – the key that needs to be removed

value – value expected to be associated with the specified key

Returns

the previous value associated with key, or null if there was no mapping for key

Throw

NullPointerException.

Example 1

Test it Now

Output:

HashMap values :   {k1=100, k2=200, k3=300, k4=400}  New HashMap after remove :   {k1=100, k3=300, k4=400}  

Example 2

Test it Now

Output:

HashMap values :   {k1=100, k2=200, k3=300, k4=400}  New HashMap after remove :   {k1=100, k3=300, k4=400}  

You may also like