LinkedHashMap<K, V>.fromIterable constructor

LinkedHashMap<K, V>.fromIterable(
  1. Iterable iterable,
  2. {K key(
    1. dynamic element
  3. V value(
    1. dynamic element

Creates a LinkedHashMap 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 both default to the identity function. Example:

final numbers = [11, 12, 13, 14];
final mapFromIterable =
    LinkedHashMap.fromIterable(numbers, key: (i) => i, value: (i) => i * i);
print(mapFromIterable); // {11: 121, 12: 144, 13: 169, 14: 196}


factory LinkedHashMap.fromIterable(Iterable iterable,
    {K Function(dynamic element)? key, V Function(dynamic element)? value}) {
  LinkedHashMap<K, V> map = LinkedHashMap<K, V>();
  MapBase._fillMapWithMappedIterable(map, iterable, key, value);
  return map;