Home » Java ConcurrentHashMap merge() Method

Java ConcurrentHashMap merge() Method

by Online Tutorials Library

Java ConcurrentHashMap merge() Method

The merge() method of ConcurrentHashMap class merge sets If the specified key is not already associated with a (non-null) value, associates it with the given value.

Syntax

Parameter

key – key with which the specified value is to be associated

value – the value to use if absent

remappingFunction – the function to recompute a value if present

Returns

The new value associated with the specified key, or null if none

Throws

No Exception is thrown.

Example 1

Test it Now

Output:

{1=Java,C, 2=php,C++, 3=.net,Rubi, 5=python,Java Script}  

Example 2

Test it Now

Output:

{1=A,F, 2=B,G, 3=C,H, 5=E,I}  

You may also like