加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090420191519/http://developer.android.com:80/reference/java/util/Set.html
public interface

Set

implements Collection<E>
java.util.Set<E>
Known Indirect Subclasses

Class Overview

Set is a collection which does not allow duplicate elements.

Summary

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

Public Methods

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
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

public abstract 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
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

public abstract void clear ()

Removes all elements from this Set, leaving it empty.

Throws
UnsupportedOperationException when removing from this Set is not supported
See Also

public abstract 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 abstract 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 abstract 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.
See Also

public abstract int hashCode ()

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

Returns
  • the receiver's hash
See Also

public abstract boolean isEmpty ()

Returns if this Set has no elements, a size of zero.

Returns
  • true if this Set has no elements, false otherwise
See Also

public abstract Iterator<E> iterator ()

Returns an Iterator on the elements of this Set.

Returns
  • an Iterator on the elements of this Set
See Also

public abstract 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
Throws
UnsupportedOperationException when removing from this Set is not supported

public abstract 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
Throws
UnsupportedOperationException when removing from this Set is not supported

public abstract 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
Throws
UnsupportedOperationException when removing from this Set is not supported

public abstract int size ()

Returns the number of elements in this Set.

Returns
  • the number of elements in this Set

public abstract 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
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

public abstract Object[] toArray ()

Returns an array containing all elements contained in this Set.

Returns
  • an array of the elements from this Set