W3cubDocs

/Dart 2

Map<K, V>.fromIterables constructor

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

Creates a Map instance associating the given keys to values.

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

This constructor iterates over keys and values and maps each element of keys to the corresponding element of values.

List<String> letters = ['b', 'c'];
List<String> words = ['bad', 'cat'];
Map<String, String> map = new Map.fromIterables(letters, words);
map['b'] + map['c'];  // badcat

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

The two Iterables must have the same length.

Implementation

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

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/Map/Map.fromIterables.html