E
- the type of a set elementpublic class Set<E>
extends java.lang.Object
implements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable
union(Set, Set)
/union(Collection)
/union(Set[])
intersection(Set, Set)
/intersection(Collection)
/intersection(Set[])
complement(Set, Set)
symDifference(Set, Set)
ArrayList
.
parse(String, ElementParser, String)
to convert a string representation of a set into a concrete object.Modifier and Type | Class and Description |
---|---|
static class |
Set.DoubleElementParser
A default parser for double elements.
|
static class |
Set.FloatElementParser
A default parser for float elements.
|
static class |
Set.IntegerElementParser
A default parser for integer elements.
|
static class |
Set.LongElementParser
A default parser for long elements.
|
static class |
Set.NumberElementParser
A default parser for number elements.
|
static class |
Set.StringElementParser
A default parser for string elements.
|
Constructor and Description |
---|
Set()
Creates an empty set with an initial capacity of ten.
|
Set(java.util.Collection<? extends E> c)
Creates a set with the specified elements in the given collection.
|
Set(E[] elements)
Creates a set with the specified elements in the given array.
|
Set(int capacity)
Creates an empty set with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Adds a new element to the set.
|
boolean |
addAll(java.util.Collection<? extends E> c) |
boolean |
addAll(E[] a)
Adds all of the elements in the specified array to this set if they're not already present (optional operation).
|
java.util.List<E> |
asList()
Gets the set of elements as a list.
|
void |
clear() |
Set<E> |
clone()
Gets a shallow copy of this set (the elements in the set are not cloned).
|
static <E> Set<E> |
complement(Set<? extends E> set1,
Set<? extends E> set2)
Computes the complement of the two specified sets that means a set which contains only elements that
are in the first set but not in the second one.
|
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
boolean |
containsAll(E[] a)
Returns
true if this set contains all of the elements in the specified array. |
boolean |
equals(java.util.Collection<E> set)
Indicates whether this set equals the given collection.
|
boolean |
equals(java.lang.Object o)
Indicates whether this set equals the specified one.
|
E |
get(int index)
Gets a specific element of the set at the given index.
|
int |
hashCode() |
static <E> Set<E> |
intersection(java.util.Collection<Set<? extends E>> sets)
Computes the intersection of the specified sets in the given collection that means a set which contains only elements that
are in all the sets, but no other elements.
|
static <E> Set<E> |
intersection(Set<? extends E>[] sets)
Computes the intersection of the specified sets in the given collection that means a set which contains only elements that
are in all the sets, but no other elements.
|
static <E> Set<E> |
intersection(Set<? extends E> set1,
Set<? extends E> set2)
Computes the intersection of the two specified sets that means a set which contains only elements that
are in both sets, but no other elements.
|
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
static <E> Set<E> |
parse(java.lang.String set,
ElementParser<E> parser)
Parses a string representation of a set into a
Set object. |
static <E> Set<E> |
parse(java.lang.String set,
ElementParser<E> parser,
java.lang.String delimiter)
Parses a string representation of a set into a
Set object. |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
removeAll(E[] a)
Removes all of this set's elements that are also contained in the specified array.
|
boolean |
retainAll(java.util.Collection<?> c) |
boolean |
retainAll(E[] a)
Retains only the elements in this set that are contained in the specified array (optional operation).
|
int |
size() |
static <E> Set<E> |
symDifference(Set<? extends E> set1,
Set<? extends E> set2)
Computes the symmetric difference of the two specified sets which is defined as:
(set1 complement set2) union (set2 complement set1) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] t) |
java.lang.String |
toString() |
static <E> Set<E> |
union(java.util.Collection<Set<? extends E>> sets)
Computes the union of the specified sets in the given collection that means a set with all distinct elements
of the sets.
|
static <E> Set<E> |
union(Set<? extends E>[] sets)
Computes the union of the specified sets in the given array that means a set with all distinct elements
of the sets.
|
static <E> Set<E> |
union(Set<? extends E> set1,
Set<? extends E> set2)
Computes the union of the two specified sets that means a set with all distinct elements of set 1 and set 2.
|
public Set()
public Set(int capacity)
capacity
- the initial capacity of the setpublic Set(E[] elements) throws java.lang.IllegalArgumentException
elements
- the elements the set should contain initiallyjava.lang.NullPointerException
- java.lang.IllegalArgumentException
public Set(java.util.Collection<? extends E> c) throws java.lang.NullPointerException
c
- the collectionjava.lang.NullPointerException
- public boolean add(E e) throws java.lang.NullPointerException
public boolean addAll(java.util.Collection<? extends E> c)
public boolean addAll(E[] a)
a
- array containing elements to be added to this settrue
if this set changed as a result of the call
- public void clear()
public boolean contains(java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
public boolean containsAll(E[] a) throws java.lang.NullPointerException
true
if this set contains all of the elements in the specified array.a
- array to be checked for containment in this collectiontrue
if this set contains all of the elements in the specified arrayjava.lang.NullPointerException
- public boolean isEmpty()
public java.util.Iterator<E> iterator()
public boolean remove(java.lang.Object o)
public boolean removeAll(java.util.Collection<?> c)
public boolean removeAll(E[] a)
a
- array containing elements to be removed from this settrue
if this collection changed as a result of the calljava.lang.NullPointerException
- public boolean retainAll(java.util.Collection<?> c)
public boolean retainAll(E[] a) throws java.lang.NullPointerException
a
- array containing elements to be retained in this settrue
if this set changed as a result of the calljava.lang.NullPointerException
- public int size()
public E get(int index) throws java.lang.IndexOutOfBoundsException
index
- the indexjava.lang.IndexOutOfBoundsException
- index < 0 || index >= size()
)public java.lang.Object[] toArray()
public <T> T[] toArray(T[] t)
public java.util.List<E> asList()
public Set<E> clone()
clone
in class java.lang.Object
public boolean equals(java.util.Collection<E> set)
set
- another settrue
if both sets are equal otherwise false
public boolean equals(java.lang.Object o)
public int hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
public static <E> Set<E> union(Set<? extends E> set1, Set<? extends E> set2) throws java.lang.NullPointerException
set1
- the first setset2
- the second setjava.lang.NullPointerException
- public static <E> Set<E> union(java.util.Collection<Set<? extends E>> sets) throws java.lang.NullPointerException
sets
- a collection of sets which should be unifiedjava.lang.NullPointerException
- public static <E> Set<E> union(Set<? extends E>[] sets) throws java.lang.NullPointerException
sets
- an array of sets which should be unifiedjava.lang.NullPointerException
- public static <E> Set<E> intersection(Set<? extends E> set1, Set<? extends E> set2) throws java.lang.NullPointerException
set1
- the first setset2
- the second setjava.lang.NullPointerException
- public static <E> Set<E> intersection(java.util.Collection<Set<? extends E>> sets) throws java.lang.NullPointerException
sets
- a collection of sets which should be intersectedjava.lang.NullPointerException
- public static <E> Set<E> intersection(Set<? extends E>[] sets) throws java.lang.NullPointerException
sets
- an array of sets which should be intersectedjava.lang.NullPointerException
- public static <E> Set<E> complement(Set<? extends E> set1, Set<? extends E> set2) throws java.lang.NullPointerException
set1
- the first setset2
- the second setjava.lang.NullPointerException
- public static <E> Set<E> symDifference(Set<? extends E> set1, Set<? extends E> set2) throws java.lang.NullPointerException
set1
- the first setset2
- the second setjava.lang.NullPointerException
- public static <E> Set<E> parse(java.lang.String set, ElementParser<E> parser) throws java.lang.IllegalArgumentException
Set
object.
parse(String, ElementParser, String)
to specify another
delimiter.set
- the set stringparser
- the parser of the elementsjava.lang.IllegalArgumentException
- Set.StringElementParser
,
Set.NumberElementParser
,
Set.IntegerElementParser
,
Set.LongElementParser
,
Set.FloatElementParser
,
Set.DoubleElementParser
public static <E> Set<E> parse(java.lang.String set, ElementParser<E> parser, java.lang.String delimiter) throws java.lang.IllegalArgumentException
Set
object.set
- the set stringparser
- the parser of the elementsdelimiter
- the delimiter of the set elementsjava.lang.IllegalArgumentException
- Set.StringElementParser
,
Set.NumberElementParser
,
Set.IntegerElementParser
,
Set.LongElementParser
,
Set.FloatElementParser
,
Set.DoubleElementParser