A collection of unique elements.

A Set is a Collection of its elements.

Sets may be the subject of the binary union, intersection, and complement operators |, &, and ~.

value kids = girls|boys; 

Elements are compared for equality using Object.equals() or Comparable.compare(). An element may occur at most once in a set.

no type hierarchy

Attributes
hashSource Codeshared actual default Integer hash

The hash value of the value, which allows the value to be an element of a hash-based set or key of a hash-based map. Implementations must respect the constraint that:

  • if x==y then x.hash==y.hash.

Therefore, a class which refines Object.equals() must also refine hash.

Refines Object.hash
Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Collection<Element>
Attributes inherited from: Iterable<Element,Absent>
Methods
cloneSource Codeshared formal Set<Element> clone()

A shallow copy of this collection, that is, a collection with identical elements which does not change if this collection changes. If this collection is immutable, it is acceptable to return a reference to this collection. If this collection is mutable, a newly instantiated collection must be returned.

complementSource Codeshared formal Set<Element> complement<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing all the elements in this set that are not contained in the given Set.

containsSource Codeshared actual default Boolean contains(Object element)

The fundamental operation for Sets. Determines if the given value belongs to this set.

Refines Collection.contains ultimately refines Category.contains
equalsSource Codeshared actual default Boolean equals(Object that)

Two Sets are considered equal if they have the same size and if every element of the first set is also an element of the second set, as determined by contains(). Equivalently, a set is equal to a second set if it is both a subset and a superset of the second set.

exclusiveUnionSource Codeshared formal Set<Element|Other> exclusiveUnion<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing only the elements contained in either this set or the given Set, but no element contained in both sets.

intersectionSource Codeshared formal Set<Element&Other> intersection<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing only the elements that are present in both this set and the given Set.

subsetSource Codeshared default Boolean subset(Set<Object> set)

Determines if this set is a subset of the given Set, that is, if the given set contains all of the elements in this set.

supersetSource Codeshared default Boolean superset(Set<Object> set)

Determines if this set is a superset of the given Set, that is, if this set contains all of the elements in the given set.

unionSource Codeshared formal Set<Element|Other> union<Other>(Set<Other> set)
given Other satisfies Object

Returns a new Set containing all the elements of this set and all the elements of the given Set.

Inherited Methods
Methods inherited from: Category<Element>
Methods inherited from: Collection<Element>
Methods inherited from: Iterable<Element,Absent>