Android
java.util
public class

java.util.HashSet<E>

java.lang.Object
java.util.AbstractCollection<E> Collection<E>
java.util.AbstractSet<E> Set<E>
java.util.HashSet<E> Serializable Cloneable Set<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

            HashSet()
Constructs a new empty instance of HashSet.
            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.
            HashSet(Collection<? extends E> collection)
Constructs a new instance of HashSet containing the unique elements in the specified collection.

Public Methods

          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.
          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
Methods inherited from class java.util.AbstractCollection
Methods inherited from class java.lang.Object
Methods inherited from interface java.lang.Iterable
Methods inherited from interface java.util.Collection
Methods inherited from interface java.util.Set

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.

Parameters

object the object to add

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.

See Also

public Object clone()

Returns a new HashSet with the same elements and size as this HashSet.

Returns

  • a shallow copy of this HashSet

See Also

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

See Also

public Iterator<E> iterator()

Returns an Iterator on the elements of this HashSet.

Returns

  • an Iterator on the elements of this HashSet

See Also

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
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48