java.lang.Object | |||
↳ | java.util.AbstractCollection <E> | ||
↳ | java.util.AbstractList <E> | ||
↳ | java.util.ArrayList<E> |
ArrayList is an implementation of
List
, backed by an array.
All optional operations including adding, removing, and replacing elements are supported.
All elements are permitted, including null.
This class is a good choice as your default
List
implementation.
Vector
synchronizes all operations, but not necessarily in a way that's
meaningful to your application: synchronizing each call to
get
, for example, is not
equivalent to synchronizing the list and iterating over it (which is probably what you intended).
CopyOnWriteArrayList
is intended for the special case of very high
concurrency, frequent traversals, and very rare mutations.
[Expand]
Inherited Fields
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.AbstractList
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Constructs a new instance of
ArrayList
with the specified
initial capacity.
|
||||||||||
|
Constructs a new
ArrayList
instance with zero initial capacity.
|
||||||||||
|
Constructs a new instance of
ArrayList
containing the elements of
the specified collection.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Adds the specified object at the end of this
ArrayList
.
|
||||||||||
|
Inserts the specified object into this
ArrayList
at the specified
location.
|
||||||||||
|
Adds the objects in the specified collection to this
ArrayList
.
|
||||||||||
|
Inserts the objects in the specified collection at the specified location
in this List.
|
||||||||||
|
Removes all elements from this
ArrayList
, leaving it empty.
|
||||||||||
|
Returns a new
ArrayList
with the same elements, the same size and
the same capacity as this
ArrayList
.
|
||||||||||
|
Searches this
ArrayList
for the specified object.
|
||||||||||
|
Ensures that after this operation the
ArrayList
can hold the
specified number of elements without further growing.
|
||||||||||
|
Compares the specified object to this list and return true if they are
equal.
|
||||||||||
|
Returns the element at the specified location in this list.
|
||||||||||
|
Returns the hash code of this list.
|
||||||||||
|
Searches this list for the specified object and returns the index of the
first occurrence.
|
||||||||||
|
Returns if this
Collection
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.
|
||||||||||
|
Removes the object at the specified location from this list.
|
||||||||||
|
Removes one instance of the specified object from this
Collection
if one
is contained (optional).
|
||||||||||
|
Replaces the element at the specified location in this
ArrayList
with the specified object.
|
||||||||||
|
Returns the number of elements in this
ArrayList
.
|
||||||||||
|
Returns an array containing all elements contained in this
ArrayList
.
|
||||||||||
|
Returns a new array containing all elements contained in this
ArrayList
.
|
||||||||||
|
Sets the capacity of this
ArrayList
to be the same as the current
size.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Removes the objects in the specified range from the start to the end
index minus one.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.AbstractList
|
|||||||||||
From class
java.util.AbstractCollection
|
|||||||||||
From class
java.lang.Object
|
|||||||||||
From interface
java.lang.Iterable
|
|||||||||||
From interface
java.util.Collection
|
|||||||||||
From interface
java.util.List
|
Constructs a new instance of
ArrayList
with the specified
initial capacity.
capacity |
the initial capacity of this
ArrayList
.
|
---|
Constructs a new
ArrayList
instance with zero initial capacity.
Constructs a new instance of
ArrayList
containing the elements of
the specified collection.
collection | the collection of elements to add. |
---|
Adds the specified object at the end of this
ArrayList
.
object | the object to add. |
---|
Inserts the specified object into this
ArrayList
at the specified
location. The object is inserted before any previous element at the
specified location. If the location is equal to the size of this
ArrayList
, the object is added at the end.
index | the index at which to insert the object. |
---|---|
object | the object to add. |
IndexOutOfBoundsException |
when
location < 0 || location > size()
|
---|
Adds the objects in the specified collection to this
ArrayList
.
collection | the collection of objects. |
---|
true
if this
ArrayList
is modified,
false
otherwise.
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.
index | the index at which to insert. |
---|---|
collection | the collection of objects. |
true
if this
ArrayList
is modified,
false
otherwise.
IndexOutOfBoundsException |
when
location < 0 || location > size()
|
---|
Returns a new
ArrayList
with the same elements, the same size and
the same capacity as this
ArrayList
.
ArrayList
Searches this
ArrayList
for the specified object.
object | the object to search for. |
---|
true
if
object
is an element of this
ArrayList
,
false
otherwise
Ensures that after this operation the
ArrayList
can hold the
specified number of elements without further growing.
minimumCapacity | the minimum capacity asked for. |
---|
Compares the specified object to this list and return true if they are equal. Two lists are equal when they both contain the same objects in the same order.
o | the object to compare to this object. |
---|
true
if the specified object is equal to this list,
false
otherwise.
Returns the element at the specified location in this list.
index | the index of the element to return. |
---|
Returns the hash code of this list. The hash code is calculated by taking each element's hashcode into account.
Searches this list for the specified object and returns the index of the first occurrence.
object | the object to search for. |
---|
Returns if this
Collection
contains no elements. This implementation
tests, whether
size
returns 0.
true
if this
Collection
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.
Searches this list for the specified object and returns the index of the last occurrence.
object | the object to search for. |
---|
Removes the object at the specified location from this list.
index | the index of the object to remove. |
---|
IndexOutOfBoundsException |
when
location < 0 || location >= size()
|
---|
Removes one instance of the specified object from this
Collection
if one
is contained (optional). This implementation iterates over this
Collection
and tests for each element
e
returned by the iterator,
whether
e
is equal to the given object. If
object != null
then this test is performed using
object.equals(e)
, otherwise
using
object == null
. If an element equal to the given object is
found, then the
remove
method is called on the iterator and
true
is returned,
false
otherwise. If the iterator does
not support removing elements, an
UnsupportedOperationException
is thrown.
object | the object to remove. |
---|
true
if this
Collection
is modified,
false
otherwise.
Replaces the element at the specified location in this
ArrayList
with the specified object.
index | the index at which to put the specified object. |
---|---|
object | the object to add. |
IndexOutOfBoundsException |
when
location < 0 || location >= size()
|
---|
Returns the number of elements in this
ArrayList
.
ArrayList
.
Returns an array containing all elements contained in this
ArrayList
. 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
ArrayList
, the array element following the collection elements
is set to null.
contents | the array. |
---|
ArrayList
.
ArrayStoreException |
when the type of an element in this
ArrayList
cannot
be stored in the type of the specified array.
|
---|
Returns a new array containing all elements contained in this
ArrayList
.
ArrayList
Sets the capacity of this
ArrayList
to be the same as the current
size.
Removes the objects in the specified range from the start to the end index minus one.
fromIndex | the index at which to start removing. |
---|---|
toIndex | the index after the last element to remove. |