Java · OOP, JVM and backend craft

When would you use ArrayList versus LinkedList?

Mediumarraylistlinkedlistdata structuresUpdated Oct 2026
Quiz this track

Short answer

ArrayList is a resizable array with O(1) random access and good cache locality. LinkedList is a doubly linked list with O(1) inserts at a known node but O(n) access and higher memory per element.

ArrayList stores elements in a contiguous array. Appending is amortized O(1) because the array grows geometrically. Inserting or removing in the middle shifts elements and costs O(n). Random access is O(1).

LinkedList stores a node per element with prev and next references. Inserting or removing at a node you already hold is O(1), but finding that node is O(n). Memory overhead is higher per element, and pointer chasing hurts CPU cache behaviour.

java
List<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add(0, "first");

Deque<String> queue = new ArrayDeque<>();
queue.addLast("job");
String next = queue.pollFirst();
ArrayList suits indexed access. ArrayDeque, not LinkedList, is the usual queue choice.

Practical guidance

  • Default to ArrayList for lists
  • Use ArrayDeque for stack and queue behaviour
  • Use LinkedList only when you repeatedly insert and remove at both ends through a List interface and have measured a benefit
  • Preallocate capacity when the size is known to avoid repeated copying

Big-O alone can mislead. ArrayList often beats LinkedList even for middle inserts at realistic sizes because shifting contiguous memory is fast and cache-friendly, while following pointers is not. Measure with representative data before choosing the exotic option.

LinkedList implements both List and Deque, but ArrayDeque is faster for queue operations and uses less memory. LinkedList is rarely the right default.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why can ArrayList be faster than LinkedList for inserts?
  2. 2What is the complexity of get on each?
  3. 3Which structure would you use for a queue?
  4. 4How does capacity affect ArrayList performance?

Say it in the interview

ArrayList is backed by an array, so index access is constant time and iteration is cache-friendly. LinkedList is a doubly linked list, so inserting at a known node is constant time but finding it is linear, and each element costs extra pointers. In practice I default to ArrayList and use ArrayDeque for queues. I only consider LinkedList after measuring, because big-O hides cache effects and allocation overhead.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Java mock interview and get scored feedback on depth, clarity and confidence.