Build 1.0_r1(from source)

java.util
Class HashSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.HashSet<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
LinkedHashSet

public class HashSet<E>
extends AbstractSet<E>
implements Set<E>, Cloneable, Serializable

HashSet is an implementation of Set. All optional operations are supported, adding and removing. The elements can be any objects.

See Also:
Serialized Form

Field Summary
(package private)  HashMap<E,HashSet<E>> backingMap
           
 
Constructor Summary
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(HashMap<E,HashSet<E>> backingMap)
           
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.
 
Method Summary
 boolean add(E object)
          Adds the specified object to this HashSet.
 void clear()
          Removes all elements from this HashSet, leaving it empty.
 Object clone()
          Returns a new HashSet with the same elements and size as this HashSet.
 boolean contains(Object object)
          Searches this HashSet for the specified object.
(package private)  HashMap<E,HashSet<E>> createBackingMap(int capacity, float loadFactor)
           
 boolean isEmpty()
          Returns if this HashSet has no elements, a size of zero.
 Iterator<E> iterator()
          Returns an Iterator on the elements of this HashSet.
 boolean remove(Object object)
          Removes an occurrence of the specified object from this HashSet.
 int size()
          Returns the number of elements in this HashSet.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Field Detail

backingMap

transient HashMap<E,HashSet<E>> backingMap
Constructor Detail

HashSet

public HashSet()
Constructs a new empty instance of HashSet.


HashSet

public HashSet(int capacity)
Constructs a new instance of HashSet with the specified capacity.

Parameters:
capacity - the initial capacity of this HashSet

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

HashSet

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

HashSet

HashSet(HashMap<E,HashSet<E>> backingMap)
Method Detail

add

public boolean add(E object)
Adds the specified object to this HashSet.

Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class AbstractCollection<E>
Parameters:
object - the object to add
Returns:
true when this HashSet did not already contain the object, false otherwise

clear

public void clear()
Removes all elements from this HashSet, leaving it empty.

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface Set<E>
Overrides:
clear in class AbstractCollection<E>
See Also:
isEmpty(), size()

clone

public Object clone()
Returns a new HashSet with the same elements and size as this HashSet.

Overrides:
clone in class Object
Returns:
a shallow copy of this HashSet
See Also:
Cloneable

contains

public boolean contains(Object object)
Searches this HashSet for the specified object.

Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>
Overrides:
contains in class AbstractCollection<E>
Parameters:
object - the object to search for
Returns:
true if object is an element of this HashSet, false otherwise

isEmpty

public boolean isEmpty()
Returns if this HashSet has no elements, a size of zero.

Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>
Overrides:
isEmpty in class AbstractCollection<E>
Returns:
true if this HashSet has no elements, false otherwise
See Also:
size()

iterator

public Iterator<E> iterator()
Returns an Iterator on the elements of this HashSet.

Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Specified by:
iterator in class AbstractCollection<E>
Returns:
an Iterator on the elements of this HashSet
See Also:
Iterator

remove

public boolean remove(Object object)
Removes an occurrence of the specified object from this HashSet.

Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>
Overrides:
remove in class AbstractCollection<E>
Parameters:
object - the object to remove
Returns:
true if this HashSet is modified, false otherwise

size

public int size()
Returns the number of elements in this HashSet.

Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>
Specified by:
size in class AbstractCollection<E>
Returns:
the number of elements in this HashSet

createBackingMap

HashMap<E,HashSet<E>> createBackingMap(int capacity,
                                       float loadFactor)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature