E
- the type of the elements of this setpublic class Set<E> extends HashSet<E>
HashSet
class and is backed
by a hash table (actually a HashMap
instance).
It makes no guarantees as to the iteration order of the set; in particular,
it does not guarantee that the order will remain constant over time.
This class permits the null element.
This class offers constant time performance for the basic operations
(add, remove, contains and size), assuming the hash function disperses the
elements properly among the buckets. Iterating over this set requires time
proportional to the sum of the HashSet instance's size (the number of elements)
plus the "capacity" of the backing HashMap instance (the number of buckets).
Thus, it is very important not to set the initial capacity too high
(or the load factor too low) if iteration performance is important.
For further technical details see HashSet
.OrderedSet
,
HashSet
,
Serialized FormConstructor and Description |
---|
Set()
Constructs a new, empty set; the backing HashMap instance has default
initial capacity (16) and load factor (0.75).
|
Set(Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection.
|
Set(E[] elements)
Constructs a new set from the input array.
|
Set(int initialCapacity)
Constructs a new, empty set; the backing HashMap instance has the
specified initial capacity and default load factor (0.75).
|
Set(int initialCapacity,
float loadFactor)
Constructs a new, empty set; the backing HashMap instance has the
specified initial capacity and the specified load factor.
|
Modifier and Type | Method and Description |
---|---|
Set<E> |
copy()
Creates and returns a clone copy of this set.
|
static <E> Set<E> |
emptySet()
Returns the empty set.
|
static <E> Set<E> |
emptySet(Set<E> set)
Returns the empty set.
|
Set<E> |
intersect(ArrayList<? extends Set<? extends E>> sets)
Returns the intersection of this set and the specified set list.
|
Set<E> |
intersect(Set<? extends E> set)
Returns the intersection of this set and the specified set.
|
Set<E> |
minus(E element)
Returns the set difference of this set minus the specified element.
|
Set<E> |
minus(Set<E> minuend)
Returns the set difference of this set minus the specified minuend.
|
ArrayList<Set<E>> |
subsets(int k)
Returns the k-element subsets of this set,
i.e., each of its k-element combination, stored in an array list.
|
static <E> ArrayList<Set<E>> |
subsets(Set<E> set,
int k)
Returns the k-element subsets of a set s,
i.e., each k-element combination of s,
stored in an array list.
|
Set<E> |
unify(ArrayList<? extends Set<? extends E>> sets)
Returns the union of this set and the specified set list.
|
Set<? extends E> |
unify(Set<? extends E> set)
Returns the union of this set and the specified set.
|
add, clear, clone, contains, isEmpty, iterator, remove, size, spliterator
equals, hashCode, removeAll
addAll, containsAll, retainAll, toArray, toArray, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
parallelStream, removeIf, stream
public Set()
public Set(Collection<? extends E> c)
c
- a collectionpublic Set(int initialCapacity)
initialCapacity
- the initial capacity of the hash mapIllegalArgumentException
- - if the initial capacity is less than zeropublic Set(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity of the hash maploadFactor
- - the load factor of the backing hash mapIllegalArgumentException
- if the initial capacity is less than zero,
or if the load factor is nonpositivepublic Set(E[] elements)
Set
.
The backing HashMap instance has the
initial capacity of the array size and the default load factor (0.75).elements
- array containing the elementspublic Set<E> copy()
public Set<E> minus(Set<E> minuend)
minuend
- the set to be subtracted from this setpublic Set<E> minus(E element)
element
- the set to be subtracted from this setpublic Set<E> intersect(Set<? extends E> set)
E
or a subclass (or implementing class) of E
.set
- a setpublic Set<E> intersect(ArrayList<? extends Set<? extends E>> sets)
Set
or being of Set
itself,
and each set is expected to contain elements of
class E
or a subclass (or implementing class) of E
.sets
- a list of setspublic Set<? extends E> unify(Set<? extends E> set)
E
or a subclass (or implementing class) of E
.set
- a setpublic Set<E> unify(ArrayList<? extends Set<? extends E>> sets)
Set
or being of Set
itself,
and each set is expected to contain elements of
class E
or a subclass (or implementing class) of E
.sets
- a list of setspublic ArrayList<Set<E>> subsets(int k)
k
- an integerpublic static <E> Set<E> emptySet()
Set<String> s = Set.emptySet();Implementation note: Implementations of this method need not create a separate Set object for each call. If an explicit variable for the empty set is not desired, the method
emptySet(Set)
may be used..E
- type of elements of this setemptySet(Set)
,
Collections.emptySet()
public static <E> Set<E> emptySet(Set<E> set)
Set.emptySet(new Set<String>());This method is appropriate if an explicit variable for the empty set is not desired.
E
- type of elements of this setset
- a setemptySet()
public static <E> ArrayList<Set<E>> subsets(Set<E> set, int k)
E
- type of elements of this setset
- a setk
- an integer