ArrayList Class

Package: java.util

The ArrayList package lets you create and maintain a special type of collection object: an array list. An array list is similar to an array but averts many of the most common problems of working with arrays, specifically the following:

check.png An array list automatically resizes itself whenever necessary.

check.png An array list lets you insert elements into the middle of the collection.

check.png An array list lets you delete items.

Constructors

Constructor

Explanation

ArrayList()

Creates an array list with an initial capacity of ten elements.

ArrayList(int capacity)

Creates an array list with the specified initial capacity.

ArrayList(Collection c)

Creates an array list and copies all the elements from the specified collection into the new array list.

Methods

Method

Explanation

add(Object element)

Adds the specified object to the array list. If you specified a type when you created the array list, the object must be of the correct type.

add(int index, Object element)

Adds the specified object to the array list at the specified index position. If you specified a type when you created the array list, the object must be of ...

Get Java For Dummies Quick Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.