ArrayList

A resizable array implementation of the List interface. Allows dynamic growth and provides O(1) random access.

Syntax

java
ArrayList<Type> list = new ArrayList<>();

Parameters

ParameterTypeDescription
TypegenericThe element type stored in the list

Example

java
ArrayList<String> names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
names.remove("Alice");
System.out.println(names.size()); // 1