Java ConcurrentHashMap computeIfPresent() MethodThe computeIfPresent() method of ConcurrentHashMap class computes a new mapping given the key and its current mapped value If the value for the specified key is present. SyntaxParameterkey - key with which the specified value is to be associated remappingFunction - the function to compute a value. Returnsthe new value associated with the specified key, or null if none ThrowsNullPointerException IllegalStateException RuntimeException Example 1Test it NowOutput: HashMap values : {k1=100, k2=200, k3=300, k4=400} New HashMap after computeIfPresent : {k1=100, k2=200, k3=300, k4=500} Example 2Test it NowOutput: ConcurrentHashMap values : {A=26, B=98, C=55} new ConcurrentHashMap after computeIfPresent : {A=26, B=98, C=155}
Next TopicJava ConcurrentHashMap
|