HashSet<E>.of constructor

HashSet<E>.of(
  1. Iterable<E> elements
)

Create a hash set containing all elements.

Creates a hash set as by HashSet<E>() and adds all given elements to the set. The elements are added in order. If elements contains two entries that are equal, but not identical, then the first one is the one in the resulting set. Example:

final baseSet = <int>{1, 2, 3};
final hashSetOf = HashSet<num>.of(baseSet);
print(hashSetOf); // fx {3, 1, 2}

Implementation

factory HashSet.of(Iterable<E> elements) => HashSet<E>()..addAll(elements);