List, ArrayList, LinkedList & Queue/Deque
Master the Java Collections hierarchy, dynamic resizing in ArrayList, doubly-linked nodes in LinkedList, and ArrayDeque/PriorityQueue.
- `ArrayDeque`: Resizable circular array implementing both Queue (FIFO) and Stack (LIFO). Faster than legacy
Stack(which is synchronized) andLinkedList. - `PriorityQueue`: Binary min-heap supporting O(log n)
offer()/poll()and O(1)peek()—ideal for top-K problems and task scheduling.
Introduction
The Java Collections Framework (JCF) provides standardized, high-performance data structures and algorithms in java.util. Choosing the right collection—understanding its time complexity, memory layout, and ordering guarantees—is one of the highest-leverage skills in Java development and technical interviews.
Collections Hierarchy
Iterable<E> -> Collection<E> -> List<E>, Set<E>, Queue<E> / Deque<E>. (Note: `Map<K, V>` is a separate root interface because it maps keys to values rather than storing standalone elements.)
ArrayList vs LinkedList Deep Dive
| Feature | ArrayList | LinkedList |
|---|---|---|
| Internal Structure | Contiguous Object[] array (grows by 1.5x) | Doubly-linked Node<E> objects |
| Random Access (`get(i)`) | O(1) | O(n) traversal |
| Add/Remove at End | O(1) amortized | O(1) |
| Insert/Remove Middle | O(n) (shifts elements via System.arraycopy) | O(1) if node known, O(n) to seek |
| CPU Cache Locality | Excellent (contiguous memory) | Poor (pointer chasing across Heap) |
In practice, ArrayList outperforms LinkedList in almost every real-world workload because modern CPUs prefetch contiguous arrays efficiently.
ArrayDeque & PriorityQueue
- `ArrayDeque`: Resizable circular array implementing both Queue (FIFO) and Stack (LIFO). Faster than legacy
Stack(which is synchronized) andLinkedList. - `PriorityQueue`: Binary min-heap supporting O(log n)
offer()/poll()and O(1)peek()—ideal for top-K problems and task scheduling.
Fail-Fast Iterators
Standard java.util iterators are fail-fast: modifying a list structurally inside a for-each loop throws ConcurrentModificationException. Use iterator.remove() or list.removeIf(...) instead.
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)