public interface Set<E> extends Collection<E>
Set
is a data structure which does not allow duplicate elements.Modifier and Type | Method and Description |
---|---|
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 yet 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 specified object to this set, and returns true if they
represent the same object using a class specific comparison.
|
int |
hashCode()
Returns the hash code for this set.
|
boolean |
isEmpty()
Returns true if this set has no elements.
|
Iterator<E> |
iterator()
Returns an iterator on the elements of this set.
|
boolean |
remove(Object object)
Removes 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.
|
boolean add(E object)
add
in interface Collection<E>
object
- the object to add.true
if this set is modified, false
otherwise.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.boolean addAll(Collection<? extends E> collection)
addAll
in interface Collection<E>
collection
- the collection of objects.true
if this set is modified, false
otherwise.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.void clear()
clear
in interface Collection<E>
UnsupportedOperationException
- when removing from this set is not supported.isEmpty()
,
size()
boolean contains(Object object)
contains
in interface Collection<E>
object
- the object to search for.true
if object is an element of this set, false
otherwise.boolean containsAll(Collection<?> collection)
containsAll
in interface Collection<E>
collection
- the collection of objects.true
if all objects in the specified collection are
elements of this set, false
otherwise.boolean equals(Object object)
equals
in interface Collection<E>
equals
in class Object
object
- the object to compare with this object.true
if the object is the same as this object,
and false
if it is different from this object.hashCode()
int hashCode()
hashCode
in interface Collection<E>
hashCode
in class Object
equals(java.lang.Object)
boolean isEmpty()
isEmpty
in interface Collection<E>
true
if this set has no elements, false
otherwise.size()
Iterator<E> iterator()
boolean remove(Object object)
remove
in interface Collection<E>
object
- the object to remove.true
if this set was modified, false
otherwise.UnsupportedOperationException
- when removing from this set is not supported.boolean removeAll(Collection<?> collection)
removeAll
in interface Collection<E>
collection
- the collection of objects to remove.true
if this set was modified, false
otherwise.UnsupportedOperationException
- when removing from this set is not supported.boolean retainAll(Collection<?> collection)
retainAll
in interface Collection<E>
collection
- the collection of objects to retain.true
if this set was modified, false
otherwise.UnsupportedOperationException
- when removing from this set is not supported.int size()
size
in interface Collection<E>
Object[] toArray()
toArray
in interface Collection<E>
<T> T[] toArray(T[] array)
toArray
in interface Collection<E>
array
- the array.ArrayStoreException
- when the type of an element in this set cannot be stored in
the type of the specified array.Collection.toArray(Object[])