What is the difference between ArrayList and LinkedList?
ArrayList is backed by a resizable array, so it gives fast access by index in O(1) but is slow to insert or remove in the middle because elements shift. LinkedList is backed by nodes with pointers, so it is fast to insert or remove at the ends but slow to access by index. Use ArrayList for mostly reading by index and LinkedList for frequent inserts and removals.
The underlying difference
ArrayList stores elements in a continuous array, which is why indexing is instant. LinkedList stores each element in a node that points to the next, which is why walking to an index takes time but linking a new node is cheap.
Quick comparison
- Access by index: ArrayList O(1), LinkedList O(n).
- Insert or remove at ends: LinkedList is efficient, ArrayList may resize.
- Memory: LinkedList uses extra memory for node pointers.
- In practice: ArrayList is the default choice for most code.
Say ArrayList for read heavy work and LinkedList for insert heavy work, then add that in practice ArrayList is the sensible default because random access is common and it is cache friendly. That practical note lands well.
Common follow up questions
Related interview questions
Want the full Java guide?
Read every Java concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the Java guide All Java questions