Build 1.0_r1(from source)

java.util
Interface Set<E>

All Superinterfaces:
Collection<E>, Iterable<E>
All Known Subinterfaces:
SortedSet<E>
All Known Implementing Classes:
AbstractSet, Collections.SynchronizedSet, Collections.SynchronizedSortedSet, ConcurrentHashMap.EntrySet, ConcurrentHashMap.KeySet, CopyOnWriteArraySet, EnumSet, HashMap.HashMapEntrySet, HashSet, HugeEnumSet, IdentityHashMap.IdentityHashMapEntrySet, LinkedHashMap.LinkedHashMapEntrySet, LinkedHashSet, MiniEnumSet, TreeMap.SubMapEntrySet, TreeMap.SubMapKeySet, TreeSet

public interface Set<E>
extends Collection<E>

Set is a collection which does not allow duplicate elements.

Since:
1.2

Method Summary
 boolean add(E object)
          Adds the specified object to this Set.
 boolean addAll(Collection<? extends E> collection)
          Adds the objects in the specified Collection which do not exist in this Set.
 void clear()
          Removes all elements from this Set, leaving it empty.
 boolean contains(Object object)
          Searches this Set for the specified object.
 boolean containsAll(Collection<?> collection)
          Searches this Set for all objects in the specified Collection.
 boolean equals(Object object)
          Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
 int hashCode()
          Returns an integer hash code for the receiver.
 boolean isEmpty()
          Returns if this Set has no elements, a size of zero.
 Iterator<E> iterator()
          Returns an Iterator on the elements of this Set.
 boolean remove(Object object)
          Removes any occurrence of the specified object from this Set.
 boolean removeAll(Collection<?> collection)
          Removes all objects in the specified Collection from this Set.
 boolean retainAll(Collection<?> collection)
          Removes all objects from this Set that are not contained in the specified Collection.
 int size()
          Returns the number of elements in this Set.
 Object[] toArray()
          Returns an array containing all elements contained in this Set.
<T> T[]
toArray(T[] array)
          Returns an array containing all elements contained in this Set.
 

Method Detail

add

boolean add(E object)
Adds the specified object to this Set. The Set is not modified if it already contains the object.

Specified by:
add in interface Collection<E>
Parameters:
object - the object to add
Returns:
true if this Set is modified, false otherwise
Throws:
UnsupportedOperationException - when adding to this Set is not supported
ClassCastException - when the class of the object is inappropriate for this Set
IllegalArgumentException - when the object cannot be added to this Set

addAll

boolean addAll(Collection<? extends E> collection)
Adds the objects in the specified Collection which do not exist in this Set.

Specified by:
addAll in interface Collection<E>
Parameters:
collection - the Collection of objects
Returns:
true if this Set is modified, false otherwise
Throws:
UnsupportedOperationException - when adding to this Set is not supported
ClassCastException - when the class of an object is inappropriate for this Set
IllegalArgumentException - when an object cannot be added to this Set

clear

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

Specified by:
clear in interface Collection<E>
Throws:
UnsupportedOperationException - when removing from this Set is not supported
See Also:
isEmpty(), size()

contains

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

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

containsAll

boolean containsAll(Collection<?> collection)
Searches this Set for all objects in the specified Collection.

Specified by:
containsAll in interface Collection<E>
Parameters:
collection - the Collection of objects
Returns:
true if all objects in the specified Collection are elements of this Set, false otherwise

equals

boolean equals(Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.

Specified by:
equals in interface Collection<E>
Overrides:
equals in class Object
Parameters:
object - Object the object to compare with this object.
Returns:
boolean true if the object is the same as this object false if it is different from this object.
See Also:
hashCode()

hashCode

int hashCode()
Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Specified by:
hashCode in interface Collection<E>
Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

isEmpty

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

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

iterator

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

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

remove

boolean remove(Object object)
Removes any occurrence of the specified object from this Set.

Specified by:
remove in interface Collection<E>
Parameters:
object - the object to remove
Returns:
true if this Set is modified, false otherwise
Throws:
UnsupportedOperationException - when removing from this Set is not supported

removeAll

boolean removeAll(Collection<?> collection)
Removes all objects in the specified Collection from this Set.

Specified by:
removeAll in interface Collection<E>
Parameters:
collection - the Collection of objects to remove
Returns:
true if this Set is modified, false otherwise
Throws:
UnsupportedOperationException - when removing from this Set is not supported

retainAll

boolean retainAll(Collection<?> collection)
Removes all objects from this Set that are not contained in the specified Collection.

Specified by:
retainAll in interface Collection<E>
Parameters:
collection - the Collection of objects to retain
Returns:
true if this Set is modified, false otherwise
Throws:
UnsupportedOperationException - when removing from this Set is not supported

size

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

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

toArray

Object[] toArray()
Returns an array containing all elements contained in this Set.

Specified by:
toArray in interface Collection<E>
Returns:
an array of the elements from this Set

toArray

<T> T[] toArray(T[] array)
Returns an array containing all elements contained in this Set. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this Set, the array element following the collection elements is set to null.

Specified by:
toArray in interface Collection<E>
Parameters:
array - the array
Returns:
an array of the elements from this Set
Throws:
ArrayStoreException - when the type of an element in this Set cannot be stored in the type of the specified array

Build 1.0_r1(from source)

Please submit a feedback, bug or feature