Print the value of an entry in a map, or “Unknown” if the entry does not exist.
import public |
The getOrDefault() method returns the value of the entry in the map with the specified key. If the entry does not exist, it returns the value of the second parameter.
public |
V represents the data type of the values stored in the map.
Parameter |
Description |
key |
Required: Specifies the key of the entry from which to retrieve the value. |
def |
Required: Specifies the default value to be returned if an entry is not found. |
Returns: |
It returns the value of the entry with the specified key, or the value of the default argument if there is no entry with that key. |