Chapter VI
Data Structures in Java
A guided tour of the workhorses of the Java Collections Framework. Each page explains the shape of the structure, its complexity, and a small runnable program you can experiment with.
§ 6.0122 min§ 6.0220 min§ 6.0324 min§ 6.0428 min§ 6.0526 min§ 6.0622 min§ 6.0730 min
Arrays and ArrayList — the workhorses
Fixed-size arrays vs dynamic ArrayList. Memory layout, amortized O(1) append, and when each one shines.
LinkedList and the Deque interface
Doubly-linked nodes, O(1) insert at either end, and why LinkedList is almost never the right choice.
Stacks, queues, and ArrayDeque
LIFO, FIFO, and why java.util.Stack is a historical mistake you should avoid.
HashMap, equals, and hashCode
How hashing works, why you must override equals and hashCode together, and the load factor that keeps lookups O(1).
TreeMap, TreeSet, and ordered structures
Red-black trees under the hood. O(log n) sorted access, range queries, and floor/ceiling lookups.
PriorityQueue — heaps in disguise
Binary heaps, O(log n) insert and extract-min, and the canonical k-largest pattern.
Graphs — adjacency lists and BFS
Modeling graphs in plain Java with Map<Node, List<Node>>, then walking them breadth-first.
Practice
Test what you've learned
Take a timed exam to check your understanding of Java data structures and core language concepts.
Open Exam Center →