Java Reference
In-Depth Information
Iterator<T> iterator()
Returns an iterator for the calling object. (Iterators are discussed in Section 16.3.)
public Object[] toArray()
Returns an array containing all of the elements in the calling object. The elements in the returned
array are in the same order as in the calling object. A new array must be returned so that the
calling object has no references to the returned array.
public <E> E[] toArray(E[] a)
Note that the type parameter E is not the same as T . So, E can be any reference type; it need not
be the type T in Collection<T> . For example, E might be an ancestor type of T .
Returns an array containing all of the elements in the calling object. The elements in the
returned array are in the same order as in the calling object. The argument a is used primarily
to specify the type of the array returned. The exact details are described in the table for the
Collection<T> interface.
Throws:
ArrayStoreException if the type of a is not an ancestor type of the type of every element in
the calling object.
NullPointerException if a is null .
public int size()
Returns the number of elements in the calling object. If the calling object contains more than
Integer.MAX_VALUE elements, returns Integer.MAX_VALUE .
OPTIONAL METHODS
As with the Collection<T> interface, the following methods are optional, which
means they still must be implemented, but the implementation can simply throw an
UnsupportedOperationException if for some reason you do not want to give them a “real”
implementation. An UnsupportedOperationException is a RunTimeException and so is
not required to be caught or declared in a throws clause.
public boolean add(T element) (Optional)
Adds element to the end of the calling object's list. Normally returns true . Returns false if the
operation failed, but if the operation failed, something is seriously wrong and you will probably
get a run-time error anyway.
Throws:
UnsupportedOperationException if the add method is not supported by the calling object.
ClassCastException if the class of element prevents it from being added to the calling object.
NullPointerException if element is null and the calling object does not support null
elements.
IllegalArgumentException if some aspect of element prevents it from being added to the
calling object.
Search WWH ::




Custom Search