Home » Java ConcurrentHashMap getOrDefault() Method

Java ConcurrentHashMap getOrDefault() Method

by Online Tutorials Library

Java ConcurrentHashMap getOrDefault() Method

The getOrDefault() method of ConcurrentHashMap class returns the value to which the specified key is mapped, or the given default value if this map contains no mapping for the key.

Syntax

Parameter

key – the key whose associated value is to be returned

defaultValue – the value to return if this map contains no mapping for the given key

Returns

the mapping for the key, if present; else the default value

Throws

NullPointerException

Example 1

Test it Now

Output:

Id is : 8888 TutorAspire 

You may also like