Overview
Comprehensive working reference, hierarchy diagrams, and field guides for the Java Collections Framework
Almost everything in java.util answers to one of two root shapes:
Collection<E>: A single group of elements that can be walked one at a time. It extendsIterable<E>, allowing everyList,Set, andQueueto be traversed directly with afor-eachloop.Map<K, V>: A separate root entirely. It does not extendCollectionorIterable, because a map's contract concerns key-to-value associations rather than a single stream of elements. Iteration occurs indirectly through its three live views:keySet(),values(), andentrySet().
Architectural Hierarchy
Live Views of a Map: map.keySet() -> Set<K>, map.values() -> Collection<V>, and map.entrySet() -> Set<Map.Entry<K,V>>. All three are live views; removing elements through any view immediately mutates the backing map.
Topic Categories
Collections Master Cheatsheet
All collection and map methods, return types, parameters, and time complexity matrix
Arrays
Contiguous primitive memory, 1D operations, 2D matrices, jagged layouts, and JVM memory mechanics
Strings
Immutable character sequences, String API methods, StringBuilder buffers, and String Constant Pool
Lists
ArrayList 50% growth mechanics, LinkedList node pointers, and modern ArrayDeque stack alternatives
Queues & Deques
Throwing vs sentinel queue APIs, double-ended ArrayDeque, and PriorityQueue binary heaps
Sets
HashSet hashing invariants, LinkedHashSet insertion order, and TreeSet range queries
Maps
HashMap treeification thresholds, LinkedHashMap LRU caching, and Java 8 compute methods
Utilities & Concurrency
Collections static algorithms, ConcurrentHashMap CAS striping, and EnumSet bit vectors
Exam Prep & DSA Patterns
12 core problem archetypes, Two Sum, Monotonic Stack, Top-K, and return-type trap drills
Quick Methods Summary: Arrays, Strings, Lists, Maps
Fast-lookup snapshot of essential method signatures across the four most heavily used structures:
| Data Structure | Primary Methods | Return Type | Complexity | Key Feature / Gotcha |
|---|---|---|---|---|
| Arrays | Arrays.sort(arr) | void | O(n log n) | Dual-Pivot Quicksort for primitives, TimSort for objects |
Arrays.binarySearch(arr, key) | int | O(log n) | Precondition: array must be sorted | |
Arrays.copyOf(arr, newLen) | T[] | O(n) | Zero-padded or truncated copy | |
Arrays.deepToString(matrix) | String | O(R * C) | Formats multidimensional 2D/3D grids recursively | |
| Strings | str.charAt(index) | char | O(1) | Constant-time character lookup |
str.substring(begin, end) | String | O(k) | Half-open slice [begin, end) | |
str.split(regex) | String[] | O(n) | Regex split; escape dots as str.split("\\.") | |
sb.append(val) / reverse() | StringBuilder | O(1) amortized / O(n) | Mutable buffer; avoid String += inside loops | |
| Lists | list.get(index) / set(i, val) | E | O(1) ArrayList | Index offset lookup in ArrayList |
list.add(val) | boolean | O(1) amortized | Appends to tail; expands buffer by 50% on overflow | |
list.remove(index) vs (Object) | E / boolean | O(n) | Trap: remove(2) removes index 2, not integer 2 | |
list.subList(from, to) | List<E> | O(1) | Live view [from, to) backed by the original list | |
| Maps | map.get(key) / put(key, val) | V | O(1) amortized | Average constant-time key lookup and insertion |
map.getOrDefault(key, default) | V | O(1) amortized | Returns fallback value if key is absent | |
map.computeIfAbsent(k, fn) | V | O(1) amortized | Computes & stores value if key absent (e.g. multi-map) | |
map.merge(k, val, biFn) | V | O(1) amortized | Cleanest frequency map: map.merge(k, 1, Integer::sum) |
Comprehensive Method Reference: For the complete toolkit tables with all parameters, return types, and code examples, see the Collections Master Cheatsheet.
Performance & Complexity Matrix
| Collection | Random Access | Insert (Head) | Insert (Tail) | Delete (Element) | Ordering | Null Keys / Elements |
|---|---|---|---|---|---|---|
ArrayList | O(1) | O(n) | O(1) amortized | O(n) | Insertion order | Yes |
LinkedList | O(n) | O(1) | O(1) | O(1) | Insertion order | Yes |
ArrayDeque | O(1) | O(1) | O(1) | O(n) | FIFO / LIFO | No (throws NPE) |
HashSet | O(1) | O(1) | O(1) | O(1) | Unordered | 1 null allowed |
TreeSet | O(log n) | O(log n) | O(log n) | O(log n) | Sorted / Natural | No (throws NPE) |
HashMap | O(1) | O(1) | O(1) | O(1) | Unordered | 1 null key, any null values |
TreeMap | O(log n) | O(log n) | O(log n) | O(log n) | Sorted keys | No null keys |