W3cubDocs

/Dart 2

LinkedHashSet<E>.from constructor

LinkedHashSet<E>.from(Iterable elements)

Create a linked hash set containing all elements.

Creates a linked hash set as by new LinkedHashSet<E>() and adds each element of elements to this set in the order they are iterated.

All the elements should be instances of E. The elements iterable itself may have any element type, so this constructor can be used to down-cast a Set, for example as:

Set<SuperType> superSet = ...;
Iterable<SuperType> tmp = superSet.where((e) => e is SubType);
Set<SubType> subSet = new LinkedHashSet<SubType>.from(tmp);

Implementation

factory LinkedHashSet.from(Iterable elements) {
  LinkedHashSet<E> result = new LinkedHashSet<E>();
  for (final element in elements) {
    result.add(element);
  }
  return result;
}

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