Dart API Referencedart:coreMap<K, V>

Map<K, V> abstract class

A Map is an associative container, mapping a key to a value. Null values are supported, but null keys are not.

abstract class Map<K, V> {
 /**
  * Creates a map with the default implementation.
  */
 factory Map() => new HashMap<K, V>();

 /**
  * Creates a [Map] that contains all key value pairs of [other].
  */
 factory Map.from(Map<K, V> other) => new HashMap<K, V>.from(other);

 /**
  * Returns whether this map contains the given [value].
  */
 bool containsValue(V value);

 /**
  * Returns whether this map contains the given [key].
  */
 bool containsKey(K key);

 /**
  * Returns the value for the given [key] or null if [key] is not
  * in the map. Because null values are supported, one should either
  * use containsKey to distinguish between an absent key and a null
  * value, or use the [putIfAbsent] method.
  */
 V operator [](K key);

 /**
  * Associates the [key] with the given [value].
  */
 void operator []=(K key, V value);

 /**
  * If [key] is not associated to a value, calls [ifAbsent] and
  * updates the map by mapping [key] to the value returned by
  * [ifAbsent]. Returns the value in the map.
  *
  * It is an error to add or remove keys from map during the call to
  * [ifAbsent].
  */
 V putIfAbsent(K key, V ifAbsent());

 /**
  * Adds all key-value pairs of [other] to this map.
  *
  * If a key of [other] is already in this map, its value is overwritten.
  *
  * The operation is equivalent to doing `this[key] = value` for each key
  * and associated value in other. It iterates over [other], which must
  * therefore not change during the iteration.
  */
 void addAll(Map<K, V> other);

 /**
  * Removes the association for the given [key]. Returns the value for
  * [key] in the map or null if [key] is not in the map. Note that values
  * can be null and a returned null value does not always imply that the
  * key is absent.
  */
 V remove(K key);

 /**
  * Removes all pairs from the map.
  */
 void clear();

 /**
  * Applies [f] to each {key, value} pair of the map.
  *
  * It is an error to add or remove keys from the map during iteration.
  */
 void forEach(void f(K key, V value));

 /**
  * The keys of [this].
  */
 // TODO(floitsch): this should return a [Set].
 Iterable<K> get keys;

 /**
  * The values of [this].
  */
 Iterable<V> get values;

 /**
  * The number of {key, value} pairs in the map.
  */
 int get length;

 /**
  * Returns true if there is no {key, value} pair in the map.
  */
 bool get isEmpty;

 /**
  * Returns true if there is at least one {key, value} pair in the map.
  */
 bool get isNotEmpty;
}

Subclasses

ConstantMap<V>, HashMap<K, V>, HttpSession, IdentityMap<K, V>, LinkedHashMap<K, V>, ListMapView<E>, ObservableMap<K, V>, SplayTreeMap<K, V>, Storage

Constructors

factory Map() #

Creates a map with the default implementation.

factory Map() => new HashMap<K, V>();

factory Map.from(Map<K, V> other) #

Creates a Map that contains all key value pairs of other.

factory Map.from(Map<K, V> other) => new HashMap<K, V>.from(other);

Properties

final bool isEmpty #

Returns true if there is no {key, value} pair in the map.

bool get isEmpty;

final bool isNotEmpty #

Returns true if there is at least one {key, value} pair in the map.

bool get isNotEmpty;

final Iterable<K> keys #

The keys of this.

Iterable<K> get keys;

final int length #

The number of {key, value} pairs in the map.

int get length;

final Iterable<V> values #

The values of this.

Iterable<V> get values;

Operators

abstract V operator [](K key) #

Returns the value for the given key or null if key is not in the map. Because null values are supported, one should either use containsKey to distinguish between an absent key and a null value, or use the putIfAbsent method.

abstract void operator []=(K key, V value) #

Associates the key with the given value.

Methods

abstract void addAll(Map<K, V> other) #

Adds all key-value pairs of other to this map.

If a key of other is already in this map, its value is overwritten.

The operation is equivalent to doing this[key] = value for each key and associated value in other. It iterates over other, which must therefore not change during the iteration.

abstract void clear() #

Removes all pairs from the map.

abstract bool containsKey(K key) #

Returns whether this map contains the given key.

abstract bool containsValue(V value) #

Returns whether this map contains the given value.

abstract void forEach(void f(K key, V value)) #

Applies f to each {key, value} pair of the map.

It is an error to add or remove keys from the map during iteration.

abstract V putIfAbsent(K key, V ifAbsent()) #

If key is not associated to a value, calls ifAbsent and updates the map by mapping key to the value returned by ifAbsent. Returns the value in the map.

It is an error to add or remove keys from map during the call to ifAbsent.

abstract V remove(K key) #

Removes the association for the given key. Returns the value for key in the map or null if key is not in the map. Note that values can be null and a returned null value does not always imply that the key is absent.