Map<K, V>.fromIterables constructor Null safety

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.

List<String> letters = ['b', 'c'];
List<String> words = ['bad', 'cat'];
var map = Map.fromIterables(letters, words);
// map is {"b": "bad", "c": "cat"}

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.

Implementation

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