What is the difference between ArrayList and LinkedList?
Answer
Both implement the List interface but use different internal data structures. ArrayList uses a dynamic array — random access is O(1) (get by index is instant), but insertion/deletion in the middle is O(n) because elements must be shifted. It is better for read-heavy workloads and when frequent index-based access is needed. LinkedList uses a doubly-linked list — insertion/deletion at head or tail is O(1), but random access is O(n) because you must traverse from the start. LinkedList also implements Deque, so it can be used as a stack or queue. In practice, ArrayList outperforms LinkedList for most use cases due to better cache locality.
Previous
What is the Java Collections Framework?
Next
What is HashMap in Java and how does it work internally?
More Java Questions
View all →- Intermediate What is the Java Collections Framework?
- Intermediate What is HashMap in Java and how does it work internally?
- Intermediate What is the difference between HashMap and HashTable in Java?
- Intermediate What is the difference between HashMap and LinkedHashMap?
- Intermediate What is the difference between HashSet and TreeSet?