Create a hash set containing all elements
.
Creates a hash set as by new HashSet<E>()
and adds each element of
elements
to this set in the order they are iterated.
All the elements
should be assignable to 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 = ...;
Set<SubType> subSet =
new HashSet<SubType>.from(superSet.where((e) => e is SubType));
Source
factory HashSet.from(Iterable elements) {
HashSet<E> result = new HashSet<E>();
for (final e in elements) {
E element = e as Object/*=E*/;
result.add(element);
}
return result;
}