Home » Java ConcurrentHashMap forEach() Method

Java ConcurrentHashMap forEach() Method

by Online Tutorials Library

Java ConcurrentHashMap forEach() Method

The forEach() method of ConcurrentHashMap class performs the given action for each key, value pair.

Syntax

Parameter

parallelismThreshold – the (estimated) number of elements needed for this operation to be executed in parallel

action – the action

transformer – a function which return transformation.

Returns

true if the value was replaced

Throws

NullPointerException.

Example 1

Test it Now

Output:

New HashMap after remove :   {k1=1000, k2=200, k3=300, k4=400}      k: k1, v: 1000      k: k2, v: 200      k: k3, v: 300      k: k4, v: 400  

Example 2

Test it Now

Output:

mymap2 :{1=101, 2=102, 3=103}   mymap :{AA=Java, BB=angular, CC=JavaScript}  comparing mymap and mymap2 :false      k: AA, v: Java      k: BB, v: angular      k: CC, v: JavaScript  

You may also like