public class HashSet<E> extends AbstractSet<E> implements Set<E>
| Constructor and Description |
|---|
HashSet()
Constructs a new empty instance of
HashSet. |
HashSet(Collection<? extends E> collection)
Constructs a new instance of
HashSet containing the unique
elements in the specified collection. |
HashSet(int capacity)
Constructs a new instance of
HashSet with the specified capacity. |
HashSet(int capacity,
float loadFactor)
Constructs a new instance of
HashSet with the specified capacity
and load factor. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E object)
Adds the specified object to this
HashSet if not already present. |
void |
clear()
Removes all elements from this
HashSet, leaving it empty. |
boolean |
contains(Object object)
Searches this
HashSet for the specified object. |
boolean |
isEmpty()
Returns true if this
HashSet has no elements, false otherwise. |
Iterator<E> |
iterator()
Returns an Iterator on the elements of this
HashSet. |
boolean |
remove(Object object)
Removes the specified object from this
HashSet. |
int |
size()
Returns the number of elements in this
HashSet. |
equals, hashCode, removeAlladdAll, containsAll, retainAll, toArray, toArray, toStringpublic HashSet()
HashSet.public HashSet(int capacity)
HashSet with the specified capacity.capacity - the initial capacity of this HashSet.public HashSet(int capacity,
float loadFactor)
HashSet with the specified capacity
and load factor.capacity - the initial capacity.loadFactor - the initial load factor.public HashSet(Collection<? extends E> collection)
HashSet containing the unique
elements in the specified collection.collection - the collection of elements to add.public boolean add(E object)
HashSet if not already present.add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>object - the object to add.true when this HashSet did not already contain
the object, false otherwisepublic void clear()
HashSet, leaving it empty.public boolean contains(Object object)
HashSet for the specified object.contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>object - the object to search for.true if object is an element of this
HashSet, false otherwise.public boolean isEmpty()
HashSet has no elements, false otherwise.isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty in class AbstractCollection<E>true if this HashSet has no elements,
false otherwise.size()public boolean remove(Object object)
HashSet.remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>object - the object to remove.true if the object was removed, false otherwise.public int size()
HashSet.size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>HashSet.