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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.