HashSet (Java SE 25 & JDK 25)
- Type Parameters:
E- the type of elements maintained by this set
- All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>
- Direct Known Subclasses:
JobStateReasons, LinkedHashSet
-
Constructor Summary
Constructors
HashSet()Constructs a new, empty set; the backing
HashMapinstance has default initial capacity (16) and load factor (0.75).HashSet(int initialCapacity) Constructs a new, empty set; the backing
HashMapinstance has the specified initial capacity and default load factor (0.75).HashSet(int initialCapacity, float loadFactor) Constructs a new, empty set; the backing
HashMapinstance has the specified initial capacity and the specified load factor.Constructs a new set containing the elements in the specified collection.
-
Method Summary
booleanAdds the specified element to this set if it is not already present.
voidclear()Removes all of the elements from this set.
clone()Returns a shallow copy of this
HashSetinstance: the elements themselves are not cloned.booleanReturns
trueif this set contains the specified element.booleanisEmpty()Returns
trueif this set contains no elements.iterator()Returns an iterator over the elements in this set.
newHashSet(int numElements) Creates a new, empty HashSet suitable for the expected number of elements.
booleanRemoves the specified element from this set if it is present.
intsize()Returns the number of elements in this set (its cardinality).
toArray()Returns an array containing all of the elements in this collection.
<T> T[]toArray(T[] a) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
-
Constructor Details
-
HashSet
-
HashSet
-
HashSet
-
HashSet
-
-
Method Details
-
iterator
-
size
-
isEmpty
-
contains
-
add
-
remove
-
clear
-
clone
-
spliterator
-
toArray
-
toArray
-
newHashSet
-