Java ConcurrentHashMap forEach() MethodThe forEach() method of ConcurrentHashMap class performs the given action for each key, value pair. SyntaxParameterparallelismThreshold - the (estimated) number of elements needed for this operation to be executed in parallel action - the action transformer - a function which return transformation. Returnstrue if the value was replaced ThrowsNullPointerException. Example 1Test it NowOutput: 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 2Test it NowOutput: 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
Next TopicJava ConcurrentHashMap
|