When to Use LinkedList vs ArrayList in Java
Fast recall
Quick revision
Core answer
Practical decision-making ability between two common implementations based on actual workload patterns, not just theoretical complexity
Believing LinkedList is better for all insertion-heavy workloads without recognizing that middle insertion still requires O(n) traversal and cache effects favor ArrayList
Explain the cache locality advantage of ArrayList — contiguous array memory sits in CPU cache, while LinkedList's scattered nodes cause cache misses that make real performance worse than big-O predicts
Interview-ready guide
Interview answer
You should choose LinkedList over ArrayList in specific situations where you frequently add or remove elements at the head or tail and you rarely or never access elements by index.
The classic use case is implementing a queue or stack. If you're building a job processing queue where tasks come in at the back with addLast and get processed from the front with removeFirst, LinkedList gives you O of 1 for both those operations. ArrayList would be O of n for removeFirst because it has to shift all the remaining elements left to fill the gap.
Similarly, if you need a stack and you're using addFirst and removeFirst, that's O of 1 with LinkedList. The key thing is you have to not need random access. If your code ever calls get with an index, that's O of n in LinkedList because it has to walk through the nodes from the head or tail to reach that position.
In most real-world scenarios, though, ArrayList is actually the better choice even for insertion-heavy workloads, and that's because of cache locality. ArrayList stores elements in a contiguous array, so when the CPU loads one element, it prefetches the next bunch into cache. LinkedList nodes are scattered all over the heap, so every access might be a cache miss that stalls the CPU waiting for main memory.
In benchmarks, iterating an ArrayList can be five to ten times faster than a LinkedList of the same size purely because of cache effects. One thing that surprises freshers is that inserting in the middle of the list is O of n for both data structures. LinkedList has to traverse to the position first, which is O of n, and then updating references is O of 1.
ArrayList has to shift elements, which is O of n. So LinkedList doesn't win for middle insertion. If you need a queue or stack, you should also consider ArrayDeque.
It's a circular array that gives you O of 1 at both ends like LinkedList but with the cache performance of ArrayList. So in practice, pick LinkedList only when you specifically need the List interface combined with Deque operations, like you need both positional access and queue behavior in the same object.
When to Use LinkedList vs ArrayList in Java
Direct Answer
Choose LinkedList when you frequently add/remove at the head or tail (O(1)), use it as a Queue/Deque, and rarely access by index. For random access or iteration, ArrayList is faster thanks to cache locality — and for pure queue/stack work, prefer ArrayDeque.
Common Mistakes & Pitfalls
- Choosing
LinkedListfor "lots of insertions": Inserting at indexiis still O(n) because you must traverse to positionifirst — onlyaddFirst/addLastare truly O(1). - Ignoring
ArrayDequefor queues: For queue or stack behaviour,ArrayDequeis usually faster thanLinkedList— a resizable circular array with O(1) ends and better cache behaviour. - Overlooking cache locality: Big-O assumes all memory access is equal, but the CPU cache makes
ArrayListfaster in many sequential workloads for sequential access. - Using
LinkedListwith any indexed access: Even occasionalgetorsetby index is O(n), which kills performance on large lists.
Check your understanding
Answer these without looking back at the article.
- Is middle insertion really O(1) in LinkedList?
- What is CPU cache locality and why does it matter for ArrayList?
- What is ArrayDeque and when would you use it over LinkedList?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.