java.util
Interface Set<E>

All Superinterfaces:
Collection<E>, Iterable<E>
All Known Implementing Classes:
HashSet

public interface Set<E>
extends Collection<E>

A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.

Author:
Michael Mirwaldt

Method Summary
 boolean add(E o)
          Adds the specified element to this set if it is not already present
 boolean addAll(Collection<? extends E> c)
          Adds all of the elements in the specified collection to this set if they're not already present.
 void clear()
          Removes all of the elements from this set
 boolean contains(Object o)
          Returns true if this set contains the specified element.
 boolean containsAll(Collection<?> c)
          Returns true if this set contains all of the elements of the specified collection.
 boolean equals(Object o)
          Compares the specified object with this set for equality.
 int hashCode()
          Returns the hash code value for this set.
 boolean isEmpty()
          Returns true if this set contains no elements.
 Iterator<E> iterator()
          Returns an iterator over the elements in this set.
 boolean remove(Object o)
          Removes the specified element from this set if it is present.
 boolean removeAll(Collection<?> c)
          Removes the specified element from this set if it is present.
 boolean retainAll(Collection<?> c)
          Removes from this set all of its elements that are contained in the specified collection.
 int size()
          Retains only the elements in this set that are contained in the specified collection.
 Object[] toArray()
          Returns the number of elements in this set (its cardinality).
<T> T[]
toArray(T[] a)
          Returns an array containing all of the elements in this set.
 

Method Detail

add

boolean add(E o)
Adds the specified element to this set if it is not already present

Specified by:
add in interface Collection<E>

addAll

boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection to this set if they're not already present.

Specified by:
addAll in interface Collection<E>

clear

void clear()
Removes all of the elements from this set

Specified by:
clear in interface Collection<E>

contains

boolean contains(Object o)
Returns true if this set contains the specified element.

Specified by:
contains in interface Collection<E>

containsAll

boolean containsAll(Collection<?> c)
Returns true if this set contains all of the elements of the specified collection.

Specified by:
containsAll in interface Collection<E>

equals

boolean equals(Object o)
Compares the specified object with this set for equality.

Specified by:
equals in interface Collection<E>
Overrides:
equals in class Object

hashCode

int hashCode()
Returns the hash code value for this set.

Specified by:
hashCode in interface Collection<E>
Overrides:
hashCode in class Object

isEmpty

boolean isEmpty()
Returns true if this set contains no elements.

Specified by:
isEmpty in interface Collection<E>

iterator

Iterator<E> iterator()
Returns an iterator over the elements in this set.

Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Iterable<E>

remove

boolean remove(Object o)
Removes the specified element from this set if it is present.

Specified by:
remove in interface Collection<E>

removeAll

boolean removeAll(Collection<?> c)
Removes the specified element from this set if it is present.

Specified by:
removeAll in interface Collection<E>

retainAll

boolean retainAll(Collection<?> c)
Removes from this set all of its elements that are contained in the specified collection.

Specified by:
retainAll in interface Collection<E>

size

int size()
Retains only the elements in this set that are contained in the specified collection.

Specified by:
size in interface Collection<E>

toArray

Object[] toArray()
Returns the number of elements in this set (its cardinality).

Specified by:
toArray in interface Collection<E>

toArray

<T> T[] toArray(T[] a)
Returns an array containing all of the elements in this set.

Specified by:
toArray in interface Collection<E>