Tuesday, March 10, 2026

ArrayList in Java With Examples

The ArrayList in Java is one of the most popular and versatile collection classes, widely used because of its ability to grow dynamically. Unlike traditional arrays, you don’t need to anticipate in advance how many elements you are going to store in the ArrayList. An ArrayList automatically expands as new items are added, making it ideal for scenarios where data size is unpredictable.

Internally, however, the ArrayList isn’t a magical "elastic" structure. It starts with an underlying array of a default capacity (10 elements). When this limit is exceeded, Java creates a new array that is 1.5 times larger than the original array and efficiently copies the existing elements into it. This resizing strategy ensures smooth performance while offering the flexibility developers love about the ArrayList in Java

Refer How does ArrayList work internally in Java to know more about how does ArrayList work internally in Java.


Hierarchy of the ArrayList

To know the hierarchy of java.util.ArrayList you need to know about 2 interfaces and 2 abstract classes.

  • Collection Interface- Collection interface is the core of the Collection Framework. It must be implemented by any class that defines a collection.
  • List interface- List interface extends Collection interface. Apart from extending all the methods of the Collection interface, List interface defines some methods of its own.
  • AbstractCollection- Abstract class which implements most of the methods of the Collection interface.
  • AbstractList- Abstract class which extends AbstractCollection and implements most of the List interface.

ArrayList extends AbstractList and implements List interface too. Apart from List interface, ArrayList also implements RandomAccess, Cloneable, java.io.Serializable interfaces.