Chapter 6: ArrayLists a Java Standard Class

ArrayList

The ArrayList class is part of the java.util package of the Java standard class library.

It provides a service similar to an array in that it can store a list of values and reference them by an index. However, whereas an array remains a fixed size throughout its existence, an ArrayList object dynamically grows and shrinks as needed.

A data element can be inserted into or removed from any location (index) of an ArrayList object with a single method invocation.

The ArrayList class is part of the Collections API, a group of classes that serve to organize and manage other objects.

Unlike an array, an ArrayList is not declared to store a particular type.

An ArrayList object stores a list of references to the Object class.

A reference to any type of object can be added to an ArrayList object.

Because an ArrayList stores references, a primitive value must be stored in an appropriate wrapper class in order to be stored in an ArrayList. Figure 6.8 lists several methods of the ArrayList class.