1/33
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Stack
Last-In First-Out (LIFO) collection. Use push() to add
Queue
First-In First-Out (FIFO) collection. Use add() or offer() to enqueue
PriorityQueue
A type of Queue that orders elements based on natural ordering or a Comparator. Not FIFO.
Deque (Double-Ended Queue)
Can act as both a queue (FIFO) and stack (LIFO). Supports addFirst()
HashSet
Stores unique elements
TreeSet
Sorted set that keeps elements in natural order (or a custom Comparator). Backed by a Red-Black tree
LinkedHashSet
Maintains insertion order while still preventing duplicates. Slightly slower than HashSet.
Set iteration method
Use enhanced for loop (for (Type x : set)) or an Iterator (Iterator
HashMap
Key-value pairs
TreeMap
Sorted map ordered by keys (natural or Comparator). No null keys allowed. O(log n) operations.
LinkedHashMap
Maintains insertion order of keys. Slightly slower than HashMap.
Map iteration (keys)
for (K key : map.keySet()) { … }
Map iteration (values)
for (V value : map.values()) { … }
Map iteration (entries)
for (Map.Entry<K
Map get vs put
get(key) retrieves value or null if missing
put(key
value) inserts or replaces value.
Map containsKey vs containsValue
containsKey() checks if a key exists
containsValue() checks if any key maps to that value (slower).
Reference Semantics
When you assign or pass objects
Value Semantics
When primitive values or immutable objects (like Strings) are copied by value
Iterator syntax
Iterator
while (it.hasNext()) { Type element = it.next()
}
Iterator remove()
Safely removes elements while iterating to avoid ConcurrentModificationException.
Enhanced for loop (for-each)
for (Type x : collection) { // read-only access to elements }
HashSet vs TreeSet
HashSet — unordered
TreeSet — sorted
slower (O(log n)).
HashMap vs TreeMap
HashMap — unordered
TreeMap — sorted
no null key.
LinkedHashSet vs TreeSet
LinkedHashSet keeps insertion order
TreeSet keeps sorted order.
Map<String
List
Set
Set containing lists — duplicates determined by list equality (equals()). Order of lists in set not guaranteed.
Map<String
Set