W3cubDocs

/Dart 2

HashMap<K, V>.fromIterable constructor

HashMap<K, V>.fromIterable(Iterable iterable, { K key(dynamic element), V value(dynamic element) })

Creates a HashMap where the keys and values are computed from the iterable.

For each element of the iterable this constructor computes a key/value pair, by applying key and value respectively.

The keys of the key/value pairs do not need to be unique. The last occurrence of a key will simply overwrite any previous value.

If no values are specified for key and value the default is the identity function.

Implementation

factory HashMap.fromIterable(Iterable iterable,
    {K key(element), V value(element)}) {
  Map<K, V> map = HashMap<K, V>();
  MapBase._fillMapWithMappedIterable(map, iterable, key, value);
  return map;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-collection/HashMap/HashMap.fromIterable.html