java.util
public
interface
java.util.Set<E>
Set is a collection which does not allow duplicate elements.
Known Indirect Subclasses
Summary
Public Methods
add,
addAll,
clear,
contains,
containsAll,
equals,
hashCode,
isEmpty,
iterator,
remove,
removeAll,
retainAll,
size,
toArray,
toArray
Details
Public Methods
public
boolean
add(E object)
Adds the specified object to this Set. The Set is not modified if it
already contains the object.
Returns
- true if this Set is modified, false otherwise
public
boolean
addAll(Collection<? extends E> collection)
Adds the objects in the specified Collection which do not exist in this
Set.
Parameters
collection
| the Collection of objects |
Returns
- true if this Set is modified, false otherwise
public
void
clear()
Removes all elements from this Set, leaving it empty.
public
boolean
contains(Object object)
Searches this Set for the specified object.
Parameters
object
| the object to search for |
Returns
- true if object is an element of this Set, false otherwise
public
boolean
containsAll(Collection<?> collection)
Searches this Set for all objects in the specified Collection.
Parameters
collection
| the Collection of objects |
Returns
- true if all objects in the specified Collection are elements of
this Set, false otherwise
public
boolean
equals(Object object)
Compares the argument to the receiver, and returns true if they represent
the
same object using a class specific comparison.
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.
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
boolean
isEmpty()
Returns if this Set has no elements, a size of zero.
Returns
- true if this Set has no elements, false otherwise
public
Iterator<E>
iterator()
Returns an Iterator on the elements of this Set.
Returns
- an Iterator on the elements of this Set
public
boolean
remove(Object object)
Removes any occurrence of the specified object from this Set.
Parameters
object
| the object to remove |
Returns
- true if this Set is modified, false otherwise
public
boolean
removeAll(Collection<?> collection)
Removes all objects in the specified Collection from this Set.
Parameters
collection
| the Collection of objects to remove |
Returns
- true if this Set is modified, false otherwise
public
boolean
retainAll(Collection<?> collection)
Removes all objects from this Set that are not contained in the specified
Collection.
Parameters
collection
| the Collection of objects to retain |
Returns
- true if this Set is modified, false otherwise
public
int
size()
Returns the number of elements in this Set.
Returns
- the number of elements in this Set
public
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.
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
|
public
Object[]
toArray()
Returns an array containing all elements contained in this Set.
Returns
- an array of the elements from this Set