A collection in which each distinct element occurs at most once. Two non-identical values are considered distinct only if they are unequal, according to their own definition of value equality.
A Set
is a Collection
of its elements. Sets may not
have null elements.
A new Set
may be obtained by calling the function set()
.
value words = set { "hello", "world" }; value greetings = set { "hello", "goodbye", "hola", "adios" };
The emptySet
is a Set
with no elements.
Sets may be the subject of the binary union, intersection,
and complement operators |
, &
, and ~
.
value greetingsInWords = words & greetings; value allWords = words | greetings;
An implementation of Set
may compare elements for
equality using Object.equals()
or Comparable.compare()
.
no type hierarchy
Attributes | |
distinct | Source Codeshared actual {Element*} distinct A stream that produces every element produced by this stream exactly once. Duplicate elements of this stream are eliminated. Two elements are considered distinct unless they are both null, or unless they are both non-null and equal. For example: String("hello world".distinct) is the string This is a lazy operation and the resulting stream reflects changes to this stream. Refines Iterable.distinct |
hash | Source 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:
Therefore, a class which refines In general, Note that when executing on a Java Virtual Machine, the
64-bit Refines Object.hash |
Inherited Attributes |
Attributes inherited from: Object |
Attributes inherited from: Collection<Element> |
Attributes inherited from: Iterable<Element,Absent> |
Methods | |
clone | Source Codeshared formal Set<Element> clone() A shallow copy of this set, that is, a set with the same elements as this set, which do not change if the elements of this set change. Refines Collection.clone |
complement | Source Codeshared default Set<Element> complement<Other>(Set<Other> set) Returns a new For example: set { "hello", "world" } ~ set { 1, 2, "hello" } Produces the set |
contains | Source Codeshared actual default Boolean contains(Object element) The fundamental operation for |
defaultNullElements | Source Codeshared actual {Element*} defaultNullElements<Default>(Default defaultValue) Produces a stream containing the elements of this
stream, in the order in which they occur in this stream,
after replacing every For example, the expression { "123", "abc", "456" }.map(parseInteger).defaultNullElements(0) results in the stream Refines Iterable.defaultNullElements |
equals | Source Codeshared actual default Boolean equals(Object that) Two Refines Object.equals |
exclusiveUnion | Source Codeshared default Set<Element|Other> exclusiveUnion<Other>(Set<Other> set) Returns a new |
intersection | Source Codeshared default Set<Element&Other> intersection<Other>(Set<Other> set) Returns a new For example: set { "hello", "world" } & set { 1, 2, "hello" } Produces the set Note that, according to this definition, and even
though set { 1 } & set { 1.0 } produces the empty set |
subset | Source Codeshared default Boolean subset(Set<Object> set) Determines if this set is a subset of the given |
superset | Source Codeshared default Boolean superset(Set<Object> set) Determines if this set is a superset of the given
|
union | Source Codeshared default Set<Element|Other> union<Other>(Set<Other> set) Returns a new For example: set { "hello", "world" } | set { 1, 2, "hello" } Produces the set Note that it is possible for two sets of disjoint
element type to be considered to have elements in
common. For example, since set { 1 } | set { 1.0 } produces the set |
Inherited Methods |
Methods inherited from: Object |
Methods inherited from: Category<Element> |
Methods inherited from: Collection<Element> |
Methods inherited from: Iterable<Element,Absent> any() , by() , chain() , collect() , contains() , count() , defaultNullElements() , each() , every() , filter() , find() , findLast() , flatMap() , fold() , follow() , frequencies() , getFromFirst() , group() , indexes() , interpose() , iterator() , locate() , locateLast() , locations() , longerThan() , map() , max() , narrow() , partition() , product() , reduce() , repeat() , scan() , select() , sequence() , shorterThan() , skip() , skipWhile() , sort() , spread() , summarize() , tabulate() , take() , takeWhile() |