Android APIs
public class

HashSet

extends AbstractSet<E>
implements Set<E> Cloneable Serializable
java.lang.Object
   ↳ java.util.AbstractCollection<E>
     ↳ java.util.AbstractSet<E>
       ↳ java.util.HashSet<E>
Known Direct Subclasses

Class Overview

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

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 if not already present.
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 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.
[Expand]
Inherited Methods
From class java.util.AbstractSet
From class java.util.AbstractCollection
From class java.lang.Object
From interface java.util.Set
From interface java.util.Collection
From interface java.lang.Iterable

Public Constructors

public HashSet ()

Added in API level 1

Constructs a new empty instance of HashSet.

public HashSet (int capacity)

Added in API level 1

Constructs a new instance of HashSet with the specified capacity.

Parameters
capacity int: the initial capacity of this HashSet.

public HashSet (int capacity, float loadFactor)

Added in API level 1

Constructs a new instance of HashSet with the specified capacity and load factor.

Parameters
capacity int: the initial capacity.
loadFactor float: the initial load factor.

public HashSet (Collection<? extends E> collection)

Added in API level 1

Constructs a new instance of HashSet containing the unique elements in the specified collection.

Parameters
collection Collection: the collection of elements to add.

Public Methods

public boolean add (E object)

Added in API level 1

Adds the specified object to this HashSet if not already present.

Parameters
object E: the object to add.
Returns
boolean true when this HashSet did not already contain the object, false otherwise

public void clear ()

Added in API level 1

Removes all elements from this HashSet, leaving it empty.

See also:

public Object clone ()

Added in API level 1

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

Returns
Object a shallow copy of this HashSet.

See also:

public boolean contains (Object object)

Added in API level 1

Searches this HashSet for the specified object.

Parameters
object Object: the object to search for.
Returns
boolean true if object is an element of this HashSet, false otherwise.

public boolean isEmpty ()

Added in API level 1

Returns true if this HashSet has no elements, false otherwise.

Returns
boolean true if this HashSet has no elements, false otherwise.

See also:

public Iterator<E> iterator ()

Added in API level 1

Returns an Iterator on the elements of this HashSet.

Returns
Iterator<E> an Iterator on the elements of this HashSet.

See also:

public boolean remove (Object object)

Added in API level 1

Removes the specified object from this HashSet.

Parameters
object Object: the object to remove.
Returns
boolean true if the object was removed, false otherwise.

public int size ()

Added in API level 1

Returns the number of elements in this HashSet.

Returns
int the number of elements in this HashSet.