ArrayList vs LinkedList in Java: Which to Use? (Beginner Guide)
ArrayList vs LinkedList in Java compared: how each works, a full performance table (O(1) vs O(n)), the key insight, and why ArrayList is the sensible default for most cases.
ArrayList vs LinkedList — both implement Java's List interface, so they're interchangeable in code, but they perform very differently under the hood. Choosing the right one is a classic interview question and a real performance decision. This guide makes the difference clear so you always pick correctly.
The one-line answer
How each one works
ArrayList is backed by a resizable array — elements sit next to each other in memory. LinkedList is a chain of nodes, each holding a value and pointers to its neighbours. That structural difference explains all their performance trade-offs. (See the linked lists and arrays lessons for the deep dive.)
Performance comparison
| Operation | ArrayList | LinkedList |
|---|---|---|
| Get by index | O(1) ✓ |
O(n) — must walk |
| Add at end | O(1)* |
O(1) |
| Add/remove at start | O(n) — shifts all |
O(1) ✓ |
| Add/remove in middle | O(n) |
O(n)** |
| Memory | compact | extra per node (pointers) |
* amortised — occasionally the array resizes. ** finding the position is O(n), though the link surgery itself is O(1).
The key insight
It comes down to what you do most:
- Reading by index a lot? → ArrayList (instant jumps).
- Constantly adding/removing at the front? → LinkedList (no shifting).
- Not sure? → ArrayList. It's the sensible default and wins most real-world cases.
Both share the same interface, so switching is trivial — just change the constructor:
List<String> a = new ArrayList<>(); // default choice List<String> b = new LinkedList<>(); // only for heavy front/middle edits // both support the same methods: a.add("hello"); a.get(0); a.remove(0);
Early on I reached for LinkedList far too often, assuming "linked = fancy = faster." In reality, ArrayList is the right default in almost every case I've encountered — modern CPUs love contiguous memory, so even some operations where LinkedList looks better on paper are faster on an ArrayList in practice. My honest rule: use ArrayList unless you have a specific, measured reason not to (heavy front insertion is the main one). Don't over-think it; pick ArrayList, and only switch if profiling tells you to. And in interviews, explaining the array-vs-nodes reason behind the trade-off matters far more than reciting which is "better."