A collection of objects in which each object can occur only once.
That is, for each object of the element type, the object is either consideredto be in the set, or tonot be in the set.
Set implementations may consider some elements indistinguishable. Theseelements are treated as being the same for any operation on the set.
The defaultSet implementation,LinkedHashSet, considers objectsindistinguishable if they are equal with regard toObject.== andObject.hashCode.
Iterating over elements of a set may be either unorderedor ordered in some way. Examples:
- AHashSet is unordered, which means that its iteration order isunspecified,
- LinkedHashSet iterates in the insertion order of its elements, and
- a sorted set likeSplayTreeSet iterates the elements in sorted order.
It is generally not allowed to modify the set (add or remove elements) whilean operation on the set is being performed, for example during a call toforEach orcontainsAll. Nor is it allowed to modify the set whileiterating either the set itself or anyIterable that is backed by the set,such as the ones returned by methods likewhere andmap.
It is generally not allowed to modify the equality of elements (and thus nottheir hashcode) while they are in the set. Some specialized subtypes may bemore permissive, in which case they should document this behavior.
- Implemented types
- Iterable<
E>
- Iterable<
- Implementers
- Available extensions
Constructors
- Set()
- Creates an emptySet.factory
- Set.from(Iterableelements)
- Creates aSet that contains all
elements.factory - Set.identity()
- Creates an empty identitySet.factory
- Set.of(Iterable<
E> elements) - Creates aSet from
elements.factory - Set.unmodifiable(Iterable<
E> elements) - Creates an unmodifiableSet from
elements.factory
Properties
- first→ E
- The first element.no setterinherited
- firstOrNull→ T?
Available onIterable<
The first element of this iterator, orT> , provided by theIterableExtensions extensionnullif the iterable is empty.no setter- hashCode→int
- The hash code for this object.no setterinherited
- indexed→Iterable<
(int,T)> Available onIterable<
Pairs of elements of the indices and elements of this iterable.T> , provided by theIterableExtensions extensionno setter- isEmpty→bool
- Whether this collection has no elements.no setterinherited
- isNotEmpty→bool
- Whether this collection has at least one element.no setterinherited
- iterator→Iterator<
E> - An iterator that iterates over the elements of this set.no setteroverride
- last→ E
- The last element.no setterinherited
- lastOrNull→ T?
Available onIterable<
The last element of this iterable, orT> , provided by theIterableExtensions extensionnullif the iterable is empty.no setter- length→int
- The number of elements in thisIterable.no setterinherited
- nonNulls→Iterable<
T> Available onIterable<
The non-T?> , provided by theNullableIterableExtensions extensionnullelements of this iterable.no setter- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
- single→ E
- Checks that this iterable has only one element, and returns that element.no setterinherited
- singleOrNull→ T?
Available onIterable<
The single element of this iterator, orT> , provided by theIterableExtensions extensionnull.no setter- wait→Future<
List< T> > Available onIterable<
Waits for futures in parallel.Future< , provided by theFutureIterable extensionT> >no setter
Methods
- add(
Evalue)→bool - Adds
valueto the set. - addAll(
Iterable< E> elements)→ void - Adds all
elementsto this set. - any(
booltest(Eelement))→bool - Checks whether any element of this iterable satisfies
test.inherited - asNameMap(
)→Map< String,T> Available onIterable<
Creates a map from the names of enum values to the values.T> , provided by theEnumByName extension- byName(
Stringname)→ T Available onIterable<
Finds the enum value in this list with nameT> , provided by theEnumByName extensionname.- cast<
R> ()→Set< R> - Provides a view of this set as a set of
Rinstances.override - clear(
)→ void - Removes all elements from the set.
- contains(
Object?value)→bool - Whether
valueis in the set.override - containsAll(
Iterable< Object?> other)→bool - Whether this set contains all the elements of
other. - difference(
Set< Object?> other)→Set<E> - Creates a new set with the elements of this that are not in
other. - elementAt(
intindex)→ E - Returns the
indexth element.inherited - elementAtOrNull(
intindex)→ T? Available onIterable<
The element at positionT> , provided by theIterableExtensions extensionindexof this iterable, ornull.- every(
booltest(Eelement))→bool - Checks whether every element of this iterable satisfies
test.inherited - expand<
T> (Iterable< T> toElements(Eelement))→Iterable<T> - Expands each element of thisIterable into zero or more elements.inherited
- firstWhere(
booltest(Eelement), {EorElse()?})→ E - The first element that satisfies the given predicate
test.inherited - fold<
T> (TinitialValue,Tcombine(TpreviousValue,Eelement))→ T - Reduces a collection to a single value by iteratively combining eachelement of the collection with an existing valueinherited
- followedBy(
Iterable< E> other)→Iterable<E> - Creates the lazy concatenation of this iterable and
other.inherited - forEach(
voidaction(Eelement))→ void - Invokes
actionon each element of this iterable in iteration order.inherited - intersection(
Set< Object?> other)→Set<E> - Creates a new set which is the intersection between this set and
other. - join(
[Stringseparator =""])→String - Converts each element to aString and concatenates the strings.inherited
- lastWhere(
booltest(Eelement), {EorElse()?})→ E - The last element that satisfies the given predicate
test.inherited - lookup(
Object?object)→ E? - If an object equal to
objectis in the set, return it. - map<
T> (TtoElement(Ee))→Iterable< T> - The current elements of this iterable modified by
toElement.inherited - noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- reduce(
Ecombine(Evalue,Eelement))→ E - Reduces a collection to a single value by iteratively combining elementsof the collection using the provided function.inherited
- remove(
Object?value)→bool - Removes
valuefrom the set. - removeAll(
Iterable< Object?> elements)→ void - Removes each element of
elementsfrom this set. - removeWhere(
booltest(Eelement))→ void - Removes all elements of this set that satisfy
test. - retainAll(
Iterable< Object?> elements)→ void - Removes all elements of this set that are not elements in
elements. - retainWhere(
booltest(Eelement))→ void - Removes all elements of this set that fail to satisfy
test. - singleWhere(
booltest(Eelement), {EorElse()?})→ E - The single element that satisfies
test.inherited - skip(
intcount)→Iterable< E> - Creates anIterable that provides all but the first
countelements.inherited - skipWhile(
booltest(Evalue))→Iterable< E> - Creates an
Iterablethat skips leading elements whiletestis satisfied.inherited - take(
intcount)→Iterable< E> - Creates a lazy iterable of the
countfirst elements of this iterable.inherited - takeWhile(
booltest(Evalue))→Iterable< E> - Creates a lazy iterable of the leading elements satisfying
test.inherited - toList(
{boolgrowable =true})→List< E> - Creates aList containing the elements of thisIterable.inherited
- toSet(
)→Set< E> - Creates aSet with the same elements and behavior as this
Set.override - toString(
)→String - A string representation of this object.inherited
- union(
Set< E> other)→Set<E> - Creates a new set which contains all the elements of this set and
other. - where(
booltest(Eelement))→Iterable< E> - Creates a new lazyIterable with all elements that satisfy thepredicate
test.inherited - whereType<
T> ()→Iterable< T> - Creates a new lazyIterable with all elements that have type
T.inherited
Operators
- operator ==(
Objectother)→bool - The equality operator.inherited