java.util.HashSet<E>
HashSet is an implementation of Set. All optional operations are supported,
adding and removing. The elements can be any objects.
Known Direct Subclasses
Summary
Public Constructors
Public Methods
add,
addAll,
clear,
contains,
containsAll,
isEmpty,
iterator,
remove,
removeAll,
retainAll,
size,
toArray,
toArray,
toString
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
add,
addAll,
clear,
contains,
containsAll,
equals,
hashCode,
isEmpty,
iterator,
remove,
removeAll,
retainAll,
size,
toArray,
toArray
Methods inherited
from interface
java.util.Set
add,
addAll,
clear,
contains,
containsAll,
equals,
hashCode,
isEmpty,
iterator,
remove,
removeAll,
retainAll,
size,
toArray,
toArray
Details
Public Constructors
public
HashSet()
Constructs a new empty instance of HashSet.
public
HashSet(int capacity)
Constructs a new instance of HashSet with the specified capacity.
Parameters
capacity
| the initial capacity of this HashSet
|
public
HashSet(int capacity, float loadFactor)
Constructs a new instance of HashSet with the specified capacity and load
factor.
Parameters
capacity
| the initial capacity |
loadFactor
| the initial load factor
|
public
HashSet(Collection<? extends E> collection)
Constructs a new instance of HashSet containing the unique elements in
the specified collection.
Parameters
collection
| the collection of elements to add
|
Public Methods
public
boolean
add(E object)
Adds the specified object to this HashSet.
Returns
- true when this HashSet did not already contain the object, false
otherwise
public
void
clear()
Removes all elements from this HashSet, leaving it empty.
public
Object
clone()
Returns a new HashSet with the same elements and size as this HashSet.
Returns
- a shallow copy of this HashSet
public
boolean
contains(Object object)
Searches this HashSet for the specified object.
Parameters
object
| the object to search for |
Returns
- true if
object
is an element of this HashSet,
false otherwise
public
boolean
isEmpty()
Returns if this HashSet has no elements, a size of zero.
Returns
- true if this HashSet has no elements, false otherwise
public
Iterator<E>
iterator()
Returns an Iterator on the elements of this HashSet.
Returns
- an Iterator on the elements of this HashSet
public
boolean
remove(Object object)
Removes an occurrence of the specified object from this HashSet.
Parameters
object
| the object to remove |
Returns
- true if this HashSet is modified, false otherwise
public
int
size()
Returns the number of elements in this HashSet.
Returns
- the number of elements in this HashSet