The ArrayList
Chapter 14.2
What is an ArrayList?
ArrayList Methods/Operations
The ArrayList Constructors
ArrayList( ) // empty list�
ArrayList(Collection c) // initialized with elements from list c�
ArrayList(int capacity) // list with specified initial capactity.
*** The capacity is the size of the underlying array that is used to store the elements. The capacity grows automatically as elements are added to an array list.
Creating the ArrayList
import java.util.ArrayList;
ArrayList<type> name = new ArrayList<type>();
Changing Capacity Manually
Changing Capacity
void ensureCapacity(int cap)
Obtaining an Array from an ArrayList
Method:
array[] = listName.toArray();
ArrayList
LinkedList
And the Winner is…