getOrDefault method

V? getOrDefault(
  1. K key,
  2. V defaultValue
)

Retrieves the value for the specified key from the map. If the key does not exist, returns the provided defaultValue.

Example:

var map = {'first': 1, 'second': 2};
print(map.getOrDefault('third', 0)); // Output: 0

Implementation

V? getOrDefault(K key, V defaultValue) {
  return containsKey(key) ? this[key] : defaultValue;
}