public interface Set<E>
ExtendsCollection<E>, Iterable<E>
Known subtypesComponentSelector, AbstractSet, HashSet, LinkedHashSet, NavigableSet, SortedSet, TreeSet
A
Set is a data structure which does not allow duplicate elements.Methods
public abstract boolean add(E object) | Adds the specified object to this set. |
public abstract boolean addAll(Collection<? extends E> collection) | Adds the objects in the specified collection which do not exist yet in this set. |
public abstract void clear() | Removes all elements from this set, leaving it empty. |
public abstract boolean contains(Object object) | Searches this set for the specified object. |
public abstract boolean containsAll(Collection<?> collection) | Searches this set for all objects in the specified collection. |
public abstract boolean equals(Object object) | Compares the specified object to this set, and returns true if they represent the same object using a class specific comparison. |
public abstract int hashCode() | Returns the hash code for this set. |
public abstract boolean isEmpty() | Returns true if this set has no elements. |
public abstract Iterator<E> iterator() | Returns an iterator on the elements of this set. |
public abstract boolean remove(Object object) | Removes the specified object from this set. |
public abstract boolean removeAll(Collection<?> collection) | Removes all objects in the specified collection from this set. |
public abstract boolean retainAll(Collection<?> collection) | Removes all objects from this set that are not contained in the specified collection. |
public abstract int size() | Returns the number of elements in this set. |
public abstract Object[] toArray() | Returns an array containing all elements contained in this set. |
public abstract <T> T[] toArray(T[] array) | Returns an array containing all elements contained in this set. |
Inherited methods
From Collection
Method details
add
public abstract boolean add(E object)Adds the specified object to this set. The set is not modified if it
already contains the object.
Parameters
objectE- 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
public abstract boolean addAll(Collection<? extends E> collection)Adds the objects in the specified collection which do not exist yet in
this set.
Parameters
collectionCollection<? extends E>- 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
public abstract void clear()Removes all elements from this set, leaving it empty.
Throws
UnsupportedOperationException- when removing from this set is not supported.
contains
public abstract boolean contains(Object object)Searches this set for the specified object.
Parameters
objectObject- the object to search for.
Returns
true if object is an element of this set, false
otherwise.containsAll
public abstract boolean containsAll(Collection<?> collection)Searches this set for all objects in the specified collection.
Parameters
collectionCollection<?>- the collection of objects.
Returns
true if all objects in the specified collection are
elements of this set, false otherwise.equals
public abstract boolean equals(Object object)Compares the specified object to this set, and returns true if they
represent the same object using a class specific comparison.
Equality for a set means that both sets have the same size and the same
elements.
Parameters
objectObject- the object to compare with this object.
Returns
boolean
true if the object is the same as this object,
and false if it is different from this object.See also
hashCode
public abstract int hashCode()Returns the hash code for this set. Two set which are equal must return
the same value.
Returns
the hash code of this set.
See also
isEmpty
public abstract boolean isEmpty()Returns true if this set has no elements.
Returns
true if this set has no elements, false
otherwise.See also
iterator
public abstract Iterator<E> iterator()Returns an iterator on the elements of this set. The elements are
unordered.
Returns
an iterator on the elements of this set.
See also
remove
public abstract boolean remove(Object object)Removes the specified object from this set.
Parameters
objectObject- the object to remove.
Returns
true if this set was modified, false otherwise.Throws
UnsupportedOperationException- when removing from this set is not supported.
removeAll
public abstract boolean removeAll(Collection<?> collection)Removes all objects in the specified collection from this set.
Parameters
collectionCollection<?>- the collection of objects to remove.
Returns
true if this set was modified, false otherwise.Throws
UnsupportedOperationException- when removing from this set is not supported.
retainAll
public abstract boolean retainAll(Collection<?> collection)Removes all objects from this set that are not contained in the specified
collection.
Parameters
collectionCollection<?>- the collection of objects to retain.
Returns
true if this set was modified, false otherwise.Throws
UnsupportedOperationException- when removing from this set is not supported.
size
public abstract int size()Returns the number of elements in this set.
Returns
the number of elements in this set.
toArray
public abstract Object[] toArray()Returns an array containing all elements contained in this set.
Returns
an array of the elements from this set.
toArray
public abstract <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.
Parameters
arrayT[]- 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.