HashMap<K, V>.fromIterables constructor
Creates a HashMap associating the given keys
to values
.
This constructor iterates over keys
and values
and maps each element
of keys
to the corresponding element of values
.
If keys
contains the same object multiple times, the last occurrence
overwrites the previous value.
It is an error if the two Iterables don't have the same length. Example:
final keys = ['Mercury', 'Venus', 'Earth', 'Mars'];
final values = [0.06, 0.81, 1, 0.11];
final mapFromIterables = HashMap.fromIterables(keys, values);
print(mapFromIterables);
// {Earth: 1, Mercury: 0.06, Mars: 0.11, Venus: 0.81}
Implementation
factory HashMap.fromIterables(Iterable<K> keys, Iterable<V> values) {
HashMap<K, V> map = HashMap<K, V>();
MapBase._fillMapWithIterables(map, keys, values);
return map;
}