Java ConcurrentHashMap replace() MethodThe replace() method of ConcurrentHashMap class replaces the entry for a key only if it is currently mapped to some value. SyntaxParameterkey - key with which the specified value is associated oldValue - value expected to be associated with the specified key newValue - value to be associated with the specified key Returnstrue if the value was replaced ThrowNullPointerException. Example 1Test it NowOutput: HashMap values : {k1=100, k2=200, k3=300, k4=400} New HashMap after remove : {k1=1000, k2=200, k3=300, k4=400} Example 2Test it NowOutput: HashMap values : {k1=100, k2=200, k3=300, k4=400} New HashMap after remove : {k1=100, k2=2000, k3=300, k4=400}
Next TopicJava ConcurrentHashMap
|