- public class ArrayList
- extends AbstractList
- implements List, RandomAccess, Cloneable, Serializable
Resizable-array implementation of the
List interface. Implements
all optional list operations, and permits all elements, including
null. In addition to implementing the
List interface,
this class provides methods to manipulate the size of the array that is
used internally to store the list. (This class is roughly equivalent to
Vector, except that it is unsynchronized.)
The
size,
isEmpty,
get,
set,
iterator, and
listIterator operations run in constant
time. The
add operation runs in
amortized constant time,
that is, adding n elements requires O(n) time. All of the other operations
run in linear time (roughly speaking). The constant factor is low compared
to that for the
LinkedList implementation.
Each
ArrayList instance has a
capacity. The capacity is
the size of the array used to store the elements in the list. It is always
at least as large as the list size. As elements are added to an ArrayList,
its capacity grows automatically. The details of the growth policy are not
specified beyond the fact that adding an element has constant amortized
time cost.
An application can increase the capacity of an
ArrayList instance
before adding a large number of elements using the
ensureCapacity
operation. This may reduce the amount of incremental reallocation.