ArrayList vs LinkedList — When to Use Each
Fast recall
Quick revision
Core answer
Knowledge of time complexity for common operations and real-world memory layout implications
Saying LinkedList is better for insertions without specifying 'at the head/tail'; ArrayList random-access insertions are O(n) for both due to shifting vs traversal
Point out that LinkedList has higher memory overhead due to node objects and poor cache locality, making ArrayList faster in practice even for prepend-heavy workloads on modern hardware. Also mention that ArrayDeque is usually preferable to LinkedList as a queue.
Interview-ready guide
Interview answer
ArrayList and LinkedList are Java's two main List implementations, each backed by a fundamentally different data structure. The choice between them has real performance implications, and the right answer depends on how you use the collection — not just which operation you perform most.
ArrayList:
- Contiguous array — 16 references per CPU cache line; 10-100x faster iteration than LinkedList
- Random access O(1); insertion/deletion in the middle O(n) due to element shifting
- The compiler-recommended default; memory overhead ~4 bytes per element
LinkedList:
- ~40 bytes per element, each node scattered across the heap — cache miss on every access
- O(1) insert at head and tail — but ArrayDeque does this better with contiguous storage
- Only legitimate advantage: O(1) mid-list insert/delete at a position held by a ListIterator (rare)
ArrayDeque (the real LinkedList replacement):
- Contiguous circular array with head/tail pointers — O(1) at both ends with cache-friendly access
- Also the replacement for
java.util.Stack, which extends Vector and synchronizes every method unnecessarily
I recommend ArrayList as the default, ArrayDeque for stack and queue patterns, and haven't needed LinkedList in production.
ArrayList vs LinkedList — When to Use Each
Direct Answer
ArrayList uses a dynamic array — O(1) random access, O(n) insert/delete in the middle. LinkedList is a doubly-linked list — O(1) at head/tail, O(n) traversal to middle. In practice, ArrayList wins for almost all workloads due to CPU cache locality.
Common Mistakes & Pitfalls
Saying LinkedList is better for insertions without specifying 'at the head/tail'; ArrayList random-access insertions are O(n) for both due to shifting vs traversal
Check your understanding
Answer these without looking back at the article.
- Why is ArrayDeque generally preferred over LinkedList for queue use cases?
- How does ArrayList resize itself when it runs out of capacity?
- What is the initial capacity of an ArrayList and what growth factor does it use?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.