java.util.List<E> |
Known Indirect Subclasses
AbstractList<E>,
AbstractSequentialList<E>,
ArrayList<E>,
CopyOnWriteArrayList<E>,
LinkedList<E>,
Stack<E>,
Vector<E>
|
A List
is a collection which maintains an ordering for its elements. Every
element in the List
has an index. Each element can thus be accessed by its
index, with the first index being zero. Normally, List
s allow duplicate
elements, as compared to Sets, where elements have to be unique.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Inserts the specified object into this
List at the specified location. | |||||||||||
Adds the specified object at the end of this
List . | |||||||||||
Inserts the objects in the specified collection at the specified location
in this
List . | |||||||||||
Adds the objects in the specified collection to the end of this
List . | |||||||||||
Removes all elements from this
List , leaving it empty. | |||||||||||
Tests whether this
List contains the specified object. | |||||||||||
Tests whether this
List contains all objects contained in the
specified collection. | |||||||||||
Compares the given object with the
List , and returns true if they
represent the same object using a class specific comparison. | |||||||||||
Returns the element at the specified location in this
List . | |||||||||||
Returns the hash code for this
List . | |||||||||||
Searches this
List for the specified object and returns the index of the
first occurrence. | |||||||||||
Returns whether this
List contains no elements. | |||||||||||
Returns an iterator on the elements of this
List . | |||||||||||
Searches this
List for the specified object and returns the index of the
last occurrence. | |||||||||||
Returns a
List iterator on the elements of this List . | |||||||||||
Returns a list iterator on the elements of this
List . | |||||||||||
Removes the object at the specified location from this
List . | |||||||||||
Removes the first occurrence of the specified object from this
List . | |||||||||||
Removes all occurrences in this
List of each object in the specified
collection. | |||||||||||
Removes all objects from this
List that are not contained in the
specified collection. | |||||||||||
Replaces the element at the specified location in this
List with the
specified object. | |||||||||||
Returns the number of elements in this
List . | |||||||||||
Returns a
List of the specified portion of this List from the given start
index to the end index minus one. | |||||||||||
Returns an array containing all elements contained in this
List . | |||||||||||
Returns an array containing all elements contained in this
List . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface java.lang.Iterable
| |||||||||||
From interface java.util.Collection
|
Inserts the specified object into this List
at the specified location.
The object is inserted before the current element at the specified
location. If the location is equal to the size of this List
, the object
is added at the end. If the location is smaller than the size of this
List
, then all elements beyond the specified location are moved by one
position towards the end of the List
.
location | the index at which to insert. |
---|---|
object | the object to add. |
UnsupportedOperationException | when adding to this List is not supported. |
---|---|
ClassCastException | when the class of the object is inappropriate for this
List . |
IllegalArgumentException | when the object cannot be added to this List . |
IndexOutOfBoundsException | when location < 0 || location > size() |
Adds the specified object at the end of this List
.
object | the object to add. |
---|
UnsupportedOperationException | when adding to this List is not supported. |
---|---|
ClassCastException | when the class of the object is inappropriate for this
List . |
IllegalArgumentException | when the object cannot be added to this List . |
Inserts the objects in the specified collection at the specified location
in this List
. The objects are added in the order they are returned from
the collection's iterator.
location | the index at which to insert. |
---|---|
collection | the collection of objects to be inserted. |
List
has been modified through the insertion, false
otherwise (i.e. if the passed collection was empty).UnsupportedOperationException | when adding to this List is not supported. |
---|---|
ClassCastException | when the class of an object is inappropriate for this
List . |
IllegalArgumentException | when an object cannot be added to this List . |
IndexOutOfBoundsException | when location < 0 || > size() |
Adds the objects in the specified collection to the end of this List
. The
objects are added in the order in which they are returned from the
collection's iterator.
collection | the collection of objects. |
---|
true
if this List
is modified, false
otherwise
(i.e. if the passed collection was empty).UnsupportedOperationException | when adding to this List is not supported. |
---|---|
ClassCastException | when the class of an object is inappropriate for this
List . |
IllegalArgumentException | when an object cannot be added to this List . |
Removes all elements from this List
, leaving it empty.
UnsupportedOperationException | when removing from this List is not supported. |
---|
Tests whether this List
contains the specified object.
object | the object to search for. |
---|
true
if object is an element of this List
, false
otherwiseTests whether this List
contains all objects contained in the
specified collection.
collection | the collection of objects |
---|
true
if all objects in the specified collection are
elements of this List
, false
otherwise.Compares the given object with the List
, and returns true if they
represent the same object using a class specific comparison. For
List
s, this means that they contain the same elements in exactly the same
order.
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.Returns the element at the specified location in this List
.
location | the index of the element to return. |
---|
IndexOutOfBoundsException | when location < 0 || >= size() |
---|
Returns the hash code for this List
. It is calculated by taking each
element' hashcode and its position in the List
into account.
List
.Searches this List
for the specified object and returns the index of the
first occurrence.
object | the object to search for. |
---|
Returns whether this List
contains no elements.
true
if this List
has no elements, false
otherwise.Returns an iterator on the elements of this List
. The elements are
iterated in the same order as they occur in the List
.
List
.Searches this List
for the specified object and returns the index of the
last occurrence.
object | the object to search for. |
---|
Returns a List
iterator on the elements of this List
. The elements are
iterated in the same order that they occur in the List
.
List
iterator on the elements of this List
Returns a list iterator on the elements of this List
. The elements are
iterated in the same order as they occur in the List
. The iteration
starts at the specified location.
location | the index at which to start the iteration. |
---|
List
.IndexOutOfBoundsException | when location < 0 || location > size() |
---|
Removes the object at the specified location from this List
.
location | the index of the object to remove. |
---|
UnsupportedOperationException | when removing from this List is not supported. |
---|---|
IndexOutOfBoundsException | when location < 0 || >= size() |
Removes the first occurrence of the specified object from this List
.
object | the object to remove. |
---|
List
was modified by this operation, false
otherwise.UnsupportedOperationException | when removing from this List is not supported. |
---|
Removes all occurrences in this List
of each object in the specified
collection.
collection | the collection of objects to remove. |
---|
true
if this List
is modified, false
otherwise.UnsupportedOperationException | when removing from this List is not supported. |
---|
Removes all objects from this List
that are not contained in the
specified collection.
collection | the collection of objects to retain. |
---|
true
if this List
is modified, false
otherwise.UnsupportedOperationException | when removing from this List is not supported. |
---|
Replaces the element at the specified location in this List
with the
specified object. This operation does not change the size of the List
.
location | the index at which to put the specified object. |
---|---|
object | the object to insert. |
UnsupportedOperationException | when replacing elements in this List is not supported. |
---|---|
ClassCastException | when the class of an object is inappropriate for this
List . |
IllegalArgumentException | when an object cannot be added to this List . |
IndexOutOfBoundsException | when location < 0 || >= size() |
Returns the number of elements in this List
.
List
.Returns a List
of the specified portion of this List
from the given start
index to the end index minus one. The returned List
is backed by this
List
so changes to it are reflected by the other.
start | the index at which to start the sublist. |
---|---|
end | the index one past the end of the sublist. |
List
.IndexOutOfBoundsException | when start < 0, start > end or end >
size() |
---|
Returns an array containing all elements contained in this List
. 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 List
, the array element following
the collection elements is set to null.
array | the array. |
---|
List
.ArrayStoreException | when the type of an element in this List cannot be stored
in the type of the specified array. |
---|
Returns an array containing all elements contained in this List
.
List
.