0% found this document useful (0 votes)
8 views

java_data_structure_cheatsheet

This cheat sheet provides an overview of Java data structures including Arrays, Lists, Sets, Maps, and Queues, along with their core methods and functionalities. It highlights key implementations like ArrayList, LinkedList, HashSet, and HashMap, detailing their operations and characteristics. Additionally, it covers utility methods for sorting, searching, and manipulating collections.

Uploaded by

rohangoud82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

java_data_structure_cheatsheet

This cheat sheet provides an overview of Java data structures including Arrays, Lists, Sets, Maps, and Queues, along with their core methods and functionalities. It highlights key implementations like ArrayList, LinkedList, HashSet, and HashMap, detailing their operations and characteristics. Additionally, it covers utility methods for sorting, searching, and manipulating collections.

Uploaded by

rohangoud82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like