Java ConcurrentHashMap compute() MethodThe compute() method of ConcurrentHashMap class is used to compute the mapping for the specified key and its current value. 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: 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 2Test it NowOutput: ConcurrentHashMap value detail: {1=Java, 2=php, 3=.net} New ConcurrentHashMap after compute: {1=Java, 2=php (Angular), 3=.net (java Script)}
Next TopicJava ConcurrentHashMap
|