ArrayList vs LinkedList Memory Usage in Java
Fast recall
Quick revision
Core answer
ArrayList keeps element references in one backing array and may reserve unused capacity. LinkedList allocates a node for every element, and each node also holds previous and next links. Therefore LinkedList usually has much higher per-element overhead and poorer locality. Exact byte counts depend on the JVM, reference compression, and object alignment.Whether you can quantify per-element overhead and connect it to cache performance
Only comparing time complexity and ignoring memory and cache effects entirely
Explain that contiguous arrays load whole cache lines, so ArrayList iteration is dramatically faster than scattered nodes
Interview-ready guide
Interview answer
The memory difference is significant.
An ArrayList is backed by a single array, and that array just holds one object reference per element, laid out contiguously in memory. The only extra overhead is some spare capacity it keeps after growing. A LinkedList is the opposite: it allocates a separate node object for every single element.
Each node stores the value reference plus two more references, one to the previous node and one to the next, and on top of that every object carries a header. So you're looking at roughly twenty-four to forty bytes of overhead per element, just for the bookkeeping. For a large list of small values, that overhead can dwarf the actual data.
But the memory story isn't only about bytes — the bigger practical impact is cache locality. Because an ArrayList's elements sit next to each other in memory, when the CPU loads one it pulls in a whole cache line containing several neighbors, and hardware prefetching keeps the pipeline full. Iterating an ArrayList is therefore very fast.
A LinkedList's nodes are scattered all over the heap, so following each next pointer is likely a cache miss, and the CPU stalls waiting for memory. That's called pointer chasing, and it's why ArrayList often beats LinkedList in real benchmarks even when the Big-O looks comparable.
One more thing worth mentioning: if you have a List of Integer, the ints are already boxed into objects, and a LinkedList then stacks node overhead on top of that. So for memory and speed, ArrayList is usually the leaner, faster choice.
ArrayList vs LinkedList Memory Usage in Java
Direct Answer
ArrayList keeps element references in one backing array and may reserve unused capacity. LinkedList allocates a node for every element, and each node also holds previous and next links. Therefore LinkedList usually has much higher per-element overhead and poorer locality. Exact byte counts depend on the JVM, reference compression, and object alignment.
Code Example
import java.util.*;
public class MemoryShape {
public static void main(String[] args) {
// ArrayList: backing array of references, contiguous
// [ref0][ref1][ref2]... + spare capacity
List<String> arr = new ArrayList<>(1000); // pre-sized: minimal waste
// LinkedList: each add allocates a Node:
// class Node<E> { E item; Node<E> next; Node<E> prev; }
// = value ref + 2 references + object header per element
List<String> lnk = new LinkedList<>();
for (int i = 0; i < 1000; i++) lnk.add("v" + i);
// Iteration: ArrayList streams through a compact backing array of references (cache-friendly);
// LinkedList chases references across the heap (cache-hostile).
long count = arr.stream().count();
}
}
Common Mistakes & Pitfalls
- Comparing only time complexity. Memory and cache behavior often decide real performance more than Big-O.
- Underestimating node overhead. Three references plus a header per element adds up fast for large lists of small values.
- Ignoring ArrayList's spare capacity. After many growths it can hold unused slots; call
trimToSize()if memory is tight. - Forgetting boxing. A
List<Integer>already boxes each int; LinkedList then adds node overhead on top of that.
Check your understanding
Answer these without looking back at the article.
- What is CPU cache locality and why does it matter for collections?
- Does ArrayList's unused capacity waste more memory than LinkedList's overhead?
- When would LinkedList's memory cost be acceptable?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.