HashSet<E> abstract class
abstract class HashSet<E> extends Set<E> { factory HashSet() => new HashSetImplementation<E>(); /** * Creates a [Set] that contains all elements of [other]. */ factory HashSet.from(Iterable<E> other) => new HashSetImplementation<E>.from(other); }
Extends
Iterable<E> > Collection<E> > Set<E> > HashSet<E>
Subclasses
Constructors
factory HashSet() #
factory HashSet() => new HashSetImplementation<E>();
Properties
final int length #
Returns the number of elements in this collection.
int get length;
Methods
void add(E value) #
Adds value into the set. The method has no effect if value was already in the set.
void add(E value);
void addAll(Collection<E> collection) #
Adds all the elements of the given collection to the set.
void addAll(Collection<E> collection);
bool contains(E value) #
Returns true if value is in the set.
bool contains(E value);
bool containsAll(Collection<E> collection) #
Returns true if this collection contains all the elements of collection.
bool containsAll(Collection<E> collection);
bool every(bool f(E element)) #
Returns true if every elements of this collection satisify the predicate f. Returns false otherwise.
bool every(bool f(E element)) { for (E element in this) { if (!f(element)) return false; } return true; }
Collection<E> filter(bool f(E element)) #
Returns a collection with the elements of this collection that satisfy the predicate f.
The returned collection should be of the same type as the collection creating it.
An element satisfies the predicate
f if f(element)
returns true.
Collection<E> filter(bool f(E element));
void forEach(void f(E element)) #
Applies the function f to each element of this collection.
void forEach(void f(E element)) { for (E element in this) f(element); }
Set<E> intersection(Collection<E> other) #
Returns a new set which is the intersection between this set and the given collection.
Set<E> intersection(Collection<E> other);
bool isEmpty() #
Returns true if there is no element in this collection.
bool isEmpty() => !iterator().hasNext();
bool isSubsetOf(Collection<E> collection) #
Returns true if collection contains all the elements of this collection.
bool isSubsetOf(Collection<E> collection);
Collection map(f(E element)) #
Returns a new collection with the elements f(e)
for each element e
of this collection.
Subclasses of Collection should implement the map
method
to return a collection of the same general type as themselves.
E.g., List.map
should return a List.
Collection map(f(E element));
reduce(initialValue, combine(previousValue, E element)) #
Reduce a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function. Use initialValue as the initial value, and the function combine to create a new value from the previous one and an element.
Example of calculating the sum of a collection:
collection.reduce(0, (prev, element) => prev + element);
Dynamic reduce(var initialValue, Dynamic combine(var previousValue, E element)) { var value = initialValue; for (E element in this) value = combine(value, element); return value; }
bool remove(E value) #
Removes value from the set. Returns true if value was in the set. Returns false otherwise. The method has no effect if value value was not in the set.
bool remove(E value);
void removeAll(Collection<E> collection) #
Removes all the elements of the given collection from the set.
void removeAll(Collection<E> collection);
bool some(bool f(E element)) #
Returns true if one element of this collection satisfies the predicate f. Returns false otherwise.
bool some(bool f(E element)) { for (E element in this) { if (f(element)) return true; } return false; }