Java Reference
In-Depth Information
METHODS TO ADD ELEMENTS
public boolean
add(T newElement)
Adds
newElement
to the end of the calling object's list and increases its size by one. The
capacity of the calling object is increased if that is required. Returns
true
if the add was
successful. This method is often used as if it were a
void
method.
public void
add(
int
index, T newElement)
Inserts
newElement
as an element in the calling object at the specifi ed index and increases the
size of the calling object by one. Each element in the calling object with an index greater than or
equal to
index
is shifted upward to have an index that is one greater than it had previously.
The
index
must be a value greater than or equal to
0
and less than
or equal to
the size of the
calling object (before this addition).
Note that you can use this method to add an element after the last current element. The capacity
of the calling object is increased if that is required.
Throws:
IndexOutOfBoundsException
if the index is not in the prescribed range.
public boolean
addAll(Collection<?
extends
T> c)
Appends all the elements in
c
to the end of the elements in the calling object in the order
that they are enumerated by a
c
iterator. The behavior of this method is not guaranteed if the
collection
c
is the calling object or any collection including the calling object either directly
or indirectly.
Throws:
NullPointerException
if
c
is
null
.
public boolean
addAll(
int
index, Collection<?
extends
T> c)
Inserts all the elements in
c
into the calling object starting at position
index
. Elements are
inserted in the order that they are enumerated by a
c
iterator. Elements previously at positions
index
or higher are shifted to higher numbered positions.
Throws:
IndexOutOfBoundsException
if
index
is not both greater than or equal to zero and less
than
size()
.
NullPointerException
if
c
is null.
METHODS TO REMOVE ELEMENTS
public
T remove(
int
index)
Deletes the element at the specifi ed index and returns the element deleted. The size of the
calling object is decreased by one. The capacity of the calling object is not changed. Each
element in the calling object with an index greater than or equal to
index
is decreased to have
an index that is one less than the value it had previously.
The
index
must be a value greater than or equal to
0
and less than the size of the calling object
(before this removal).
Throws:
IndexOutOfBoundsException
if the
index
is not in the prescribed range.