ArrayList is the most widely used implementation of the List interface. Some of the salient features of an ArrayList are:

  1. Elements are stored in the order of insertion.
  2. It allows the storage of duplicate elements.
  3. ArrayList also supports null elements.

Internal implementation of ArrayList

An ArrayList stores data in a resizable array. Before Java 8, when an ArrayList was created, an array of default size ten was created internally. Now, when an ArrayList is created, an array of size zero is created. Only when the first element is inserted does the array size change to ten. This is called lazy initialization, and it saves a lot of memory.

Before adding an element in ArrayList, its capacity is checked. If the internal array is full, then a new array of size n+n2+1\lgroup n+\frac{n}{2}+1\rgroup is created (e.g., if the capacity is ten, then a new array of size 16 will be created). The elements from the old array will be copied to the new array. This increases the capacity of an ArrayList, which is a time-consuming process.