Javatpoint Logo
Javatpoint Logo

Java ConcurrentHashMap compute() Method

The compute() method of ConcurrentHashMap class is used to compute the mapping for the specified key and its current value.

Syntax

Parameter

key - key with which the specified value is to be associated.

remappingFunction - the function to compute a value.

Returns

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

Throws

NullPointerException

IllegalStateException

RuntimeException

Example 1

Test it Now

Output:

Values in map with detail: 
{1=1, 2=10, 3=100, 4=2, 5=20, 6=200}
Map after using  compute(): {1=1, 2=10, 3=100, 4=2, 5=20, 6=200100}

Example 2

Test it Now

Output:

ConcurrentHashMap value detail: {1=Java, 2=php, 3=.net}
New ConcurrentHashMap after compute: {1=Java, 2=php (Angular), 3=.net (java Script)}





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA