Java Reference
In-Depth Information
ListIterator<T> listIterator(
int
index)
Returns a list iterator for the calling object starting at
index
. The fi rst element to be returned by
the iterator is the one at
index
. (Iterators are discussed in Section 16.3.)
Throws:
IndexOutOfBoundsException
if
index
does not satisfy:
0 <= index <= size()
CONVERTING TO AN ARRAY
public
Object[] toArray()
Returns an array containing all of the elements in the calling object. The elements of the array are
indexed the same as in the calling object.
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 of the array are
indexed the same as in the calling object.
The argument
a
is used primarily to specify the type of the array returned. The exact details are
as follows:
The type of the returned array is that of
a
. If the collection fi ts in the array
a
, then
a
is used to
hold the elements of the returned array; otherwise a new array is created with the same type
as
a
.
If
a
has more elements than the calling object, then the element in
a
immediately following the
end of the elements copied from the calling object are set to
null
.
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
.
MEMORY MANAGEMENT
public int
size()
Returns the number of elements in the calling object.
public int
capacity()
Returns the current capacity of the calling object.
public void
ensureCapacity(
int
newCapacity)
Increases the capacity of the calling object to ensure that it can hold at least
newCapacity
elements. Using
ensureCapacity
can sometimes increase effi ciency, but its use is not needed
for any other reason.