What is the difference between an array and an ArrayList in Java?
An array is a fixed-size, strongly typed block of memory created with new. Its length is part of its type at runtime and can never change: an int[3] holds three ints forever. An ArrayList is a class in the Collections Framework that implements the List interface and holds a growable array behind the scenes. When you add beyond its capacity it allocates a bigger array and copies the contents across.
That single difference cascades into everything else. An array is faster — it has no per-element method dispatch, no bounds-check indirection beyond the length field, and no wrapper allocation. An ArrayList gives you generics, so it holds real Integer objects rather than raw values, and it gives you the whole List interface: add, remove, indexOf, iterators, subList, and the stream API.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
int[] numbers = {1, 2, 3};
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3));
System.out.println("array size : " + numbers.length);
System.out.println("list size : " + list.size());
list.add(4); // ArrayList can grow
System.out.println("list after add: " + list);
// An array cannot grow. This is a copy into a new, longer array.
int[] bigger = Arrays.copyOf(numbers, 5);
System.out.println("copied array : " + Arrays.toString(bigger));
list.set(0, 100);
System.out.println("list after set: " + list);
System.out.println("get(0) as int : " + list.get(0));
}
}The boxing line is worth noticing: list.get(0) returns an Integer, and assigning it to an int unboxes it. An ArrayList of primitives costs one wrapper object per element — except for the small values the Integer cache covers, which is why a list of small integers is far cheaper than it looks.
The last difference is mutability of size: because an array's length is fixed, inserting into the middle means allocating a new array and copying, whereas an ArrayList shifts elements in place.