Map<K, V>.fromIterables constructor

Map<K, V>.fromIterables(
  1. Iterable<K> keys,
  2. Iterable<V> values

Creates a map associating the given keys to the given values.

The map construction iterates over keys and values simultaneously, and adds an entry to the map for each pair of key and value.

final rings = <bool>[false, false, true, true];
final planets = <String>{'Earth', 'Mars', 'Jupiter', 'Saturn'};
final map = Map<String, bool>.fromIterables(planets, rings);
print(map); // {Earth: false, Mars: false, Jupiter: true, Saturn: true}

If keys contains the same object multiple times, the value of the last occurrence overwrites any previous value.

The two Iterables must have the same length.

The created map is a LinkedHashMap. A LinkedHashMap requires the keys to implement compatible operator== and hashCode. It iterates in key insertion order.


factory Map.fromIterables(Iterable<K> keys, Iterable<V> values) =
    LinkedHashMap<K, V>.fromIterables;