A collection of key/value pairs, from which you retrieve a valueusing its associated key.
There is a finite number of keys in the map,and each key has exactly one value associated with it.
Maps, and their keys and values, can be iterated.The order of iteration is defined by the individual type of map.Examples:
- The plainHashMap is unordered (no order is guaranteed),
- theLinkedHashMap iterates in key insertion order,
- and a sorted map likeSplayTreeMap iterates the keys in sorted order.
It is generally not allowed to modify the map (add or remove keys) whilean operation is being performed on the map, for example in functions calledduring aforEach call.Modifying the map while iterating the keys or valuesmay also break the iteration.
It is generally not allowed to modify the equality of keys (and thus nottheir hashcode) while they are in the map. Some specialized subtypes may bemore permissive, in which case they should document this behavior.
Key equality must be an equality relation. If the key stored in a mapand the key used for lookup do not agree on whether the two are equal,so equality is notsymmetric, then lookup behavior is unspecified.
Constructors
- Map()
- Creates an emptyLinkedHashMap.factory
- Map.from(Mapother)
- Creates aLinkedHashMap with the same keys and values as
other.factory - Map.fromEntries(Iterable<
MapEntry< entries)K,V> > - Creates a new map and adds all entries.factory
- Map.fromIterable(Iterableiterable, {Kkey(dynamicelement)?,Vvalue(dynamicelement)?})
- Creates a Map instance in which the keys and values are computed from the
iterable.factory - Map.fromIterables(Iterable<
K> keys,Iterable<V> values) - Creates a map associating the given
keysto the givenvalues.factory - Map.identity()
- Creates an identity map with the default implementation,LinkedHashMap.factory
- Map.of(Map<
K,V> other) - Creates aLinkedHashMap with the same keys and values as
other.factory - Map.unmodifiable(Mapother)
- Creates an unmodifiable hash-based map containing the entries of
other.factory
Properties
- entries→Iterable<
MapEntry< K,V> > - The map entries of thisMap.no setter
- hashCode→int
- The hash code for this object.no setterinherited
- isEmpty→bool
- Whether there is no key/value pair in the map.no setter
- isNotEmpty→bool
- Whether there is at least one key/value pair in the map.no setter
- keys→Iterable<
K> - The keys of thisMap.no setter
- length→int
- The number of key/value pairs in the map.no setter
- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
- values→Iterable<
V> - The values of thisMap.no setter
Methods
- addAll(
Map< K,V> other)→ void - Adds all key/value pairs of
otherto this map. - addEntries(
Iterable< MapEntry< newEntries)→ voidK,V> > - Adds all key/value pairs of
newEntriesto this map. - cast<
RK,RV> ()→Map< RK,RV> - Provides a view of this map as having
RKkeys andRVinstances,if necessary. - clear(
)→ void - Removes all entries from the map.
- containsKey(
Object?key)→bool - Whether this map contains the given
key. - containsValue(
Object?value)→bool - Whether this map contains the given
value. - forEach(
voidaction(Kkey,Vvalue))→ void - Applies
actionto each key/value pair of the map. - map<
K2,V2> (MapEntry< K2,V2> convert(Kkey,Vvalue))→Map<K2,V2> - Returns a new map where all entries of this map are transformed bythe given
convertfunction. - noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- putIfAbsent(
Kkey,VifAbsent())→ V - Look up the value of
key, or add a new entry if it isn't there. - remove(
Object?key)→ V? - Removes
keyand its associated value, if present, from the map. - removeWhere(
booltest(Kkey,Vvalue))→ void - Removes all entries of this map that satisfy the given
test. - toString(
)→String - A string representation of this object.inherited
- update(
Kkey,Vupdate(Vvalue), {VifAbsent()?})→ V - Updates the value for the provided
key. - updateAll(
Vupdate(Kkey,Vvalue))→ void - Updates all values.
Operators
- operator ==(
Objectother)→bool - The equality operator.inherited
- operator [](
Object?key)→ V? - The value for the given
key, ornullifkeyis not in the map. - operator []=(
Kkey,Vvalue)→ void - Associates the
keywith the givenvalue.