Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Collections Deep Dive — List, Set, Map, Queue

Compare ArrayList and LinkedList honestly. Why is LinkedList almost never the right choice in practice?

Level II · JuniorCollections Deep Dive — List, Set, Map, Queue
Short answer

ArrayList is a contiguous array: O(1) random access and cache-friendly iteration, with amortized O(1) appends and O(n) middle inserts/removes due to shifting.

Explanation

LinkedList offers O(1) insert/remove only if you already hold the node, but indexing is O(n) and every element is a separately allocated node, killing cache locality and inflating memory. In real workloads ArrayList's locality usually wins even for inserts, so LinkedList is rarely justified — its main legitimate use is as a Deque/queue, where ArrayDeque is typically still faster.

Common mistakes
  • Saying LinkedList is faster for insertion everywhere — finding the position is O(n).
  • Ignoring CPU cache locality, which favours ArrayList.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Collections Deep Dive — List, Set, Map, Queue.

Practise free

More on Collections Deep Dive — List, Set, Map, Queue