Java Data Structure Cheat Sheet
Array
Arrays are fixed-size, indexed structures storing elements of the same type.
Helper Methods (java.util.Arrays / Collections):
• Arrays.fill(arr, val) – fill all elements with val
• Arrays.sort(arr) – sort in ascending order
• Collections.reverse(Arrays.asList(arr)) – reverse order
List Interface & Implementations
List: Ordered collection allowing duplicates and positional access.
Core Methods: get(index), set(index, element), subList(from, to), add(e), remove(index), contains(o),
size(), isEmpty().
ArrayList
Resizable-array implementation with O(1) random access and amortized O(1) add.
Methods: add(e), addAll(c), remove(index), clear(), contains(o), indexOf(o), size().
LinkedList
Doubly-linked list implementing List and Deque, efficient insertions/removals at ends.
Deque Methods: addFirst(e), addLast(e), removeFirst(), removeLast(), getFirst(), getLast().
Stack
Legacy LIFO stack extending Vector, superseded by Deque.
Methods: push(item), pop(), peek(), empty(), search(o).
Set Interface & HashSet
Set: Unordered collection prohibiting duplicates.
Methods: add(e), remove(o), contains(o), size(), isEmpty(), addAll(), removeAll(), retainAll().
HashSet: Hash-table based Set offering constant-time basic operations.
Map Interface & HashMap/TreeMap
Map: Key-value mapping interface.
HashMap: put(key, value), get(key), remove(key), containsKey(key), getOrDefault(key, default).
TreeMap: Sorted map with firstKey(), lastKey().
Queue Interface & Implementations
Queue: FIFO structure with exception vs special-value methods.
Insert: add(e)/offer(e), Remove: remove()/poll(), Examine: element()/peek().
PriorityQueue: Heap-based, ordering by priority.
Deque: Double-ended queue, methods addFirst(e), addLast(e), removeFirst(), removeLast().
Collections Utilities
Sorting & Searching: sort(list), binarySearch(list, key).
Reordering: reverse(list), rotate(list, distance), shuffle(list), fill(list, obj).
Copies & Frequency: copy(dest, src), frequency(collection, obj).
Wrappers: synchronizedList, unmodifiableList, singletonList, emptyList().