java_data_structure_cheatsheet
java_data_structure_cheatsheet
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
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).
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().