Iterable ← Collection ← Queue / List / Set| Class | Initial Capacity | Growth Strategy | Backed By |
|---|---|---|---|
ArrayList | 10 | 1.5× (old + old >> 1) | Dynamic array |
Vector | 10 | 2× (doubles) | Dynamic array (synchronized) |
HashMap | 16 | 2× (doubles) at LF=0.75 | Array of Node buckets |
HashSet | 16 | 2× (doubles) at LF=0.75 | HashMap internally |
LinkedHashMap | 16 | 2× (doubles) at LF=0.75 | HashMap + doubly linked list |
TreeMap | — | — | Red-Black Tree |
TreeSet | — | — | TreeMap internally |
Hashtable | 11 | 2n + 1 | Array of Entry buckets |
PriorityQueue | 11 | < 64: +2 · ≥ 64: 1.5× | Binary heap array |
ArrayDeque | 16 | 2× (doubles) | Circular array |
ConcurrentHashMap | 16 | 2× (doubles) at LF=0.75 | Segmented Node array |
add()remove()clear()size()contains()addAll(col) | Bulk add |
binarySearch(col, item) | Binary search |
sort(list) | Natural sort |
reverse(list) | Reverse order |
shuffle(list) | Randomize |
fill(list, obj) | Fill with obj |
copy(dest, src) | Overwrites dest |
frequency(col, obj) | Count occurrences |
disjoint(c1, c2) | true if no common elements |
emptyList / emptySet | Immutable empty |
a.equals(a) | Reflexive → true |
a.equals(b) == b.equals(a) | Symmetric |
a=b, b=c → a=c | Transitive |
a.equals(null) | Always false |
| Class | Notes |
|---|---|
ArrayList | Dynamic array, random access O(1) |
Vector | Legacy, synchronized (slow) |
LinkedList | Doubly linked, slower access O(n) |
Stack | extends Vector (legacy) |
Arrays.toList(arr) | Immutable |
Arrays.asList(arr) | Fixed-size, set() allowed |
new ArrayList<>(Arrays.asList(arr)) | Fully mutable |
List.of(...) | JDK 9+ unmodifiable |
Collections.unmodifiableList() | JDK 8 |
newCap = old + (old >> 1)| Safe (returns false/null) | Throws Exception |
|---|---|
offerFirst / offerLast | addFirst / addLast |
pollFirst / pollLast | removeFirst / removeLast |
peekFirst / peekLast | getFirst / getLast |
push() / pop()offer() / poll()add() / poll() / peek() / contains() / toArray()remove(obj) is O(n) (linear search + rebalance)add() returns true if new element, false if duplicateHashMap — stores map.put(key, PRESENT)Set.of(...) → unmodifiable · JDK 8: Collections.unmodifiableSet()index = (n-1) & hash — capacity always power of 2hash ^ (hash >>> 16) (mixes high bits → reduces collisions)new HashMap<>(expectedSize / 0.75f + 1)put(k,v)remove(k)get(k)keySet()entrySet()containsKey()containsValue()putIfAbsent(k,v)isEmpty()size()equals()| Class | Order | Null Key | Thread-safe | Speed |
|---|---|---|---|---|
HashMap | None | ✓ (1) | ✗ | O(1) |
LinkedHashMap | Insert/Access | ✓ (1) | ✗ | O(1) |
TreeMap | Sorted | ✗ natural | ✗ | O(log n) |
HashTable | None | ✗ | ✓ | Slow |
ConcurrentHashMap | None | ✗ | ✓ | Fast |
EnumMap | Enum ordinal | ✗ | ✗ | O(1) |
WeakHashMap | None | ✓ | ✗ | O(1) |
NavigableMapnew TreeMap<>(Comparator.reverseOrder())new LinkedHashMap<>(16, 0.75f, true) → access-order moderemoveEldestEntry() → behaves as LRU CacheWeakReference — GC'd when key set to null. Memory-saving cache.| Reference Type | GC Behavior |
|---|---|
Strong Integer i = 10 | Never GC'd while reachable |
Soft SoftReference<> | GC'd only when JVM needs memory |
Weak WeakReference<> | GC'd immediately when unreachable |
| Method | Returns |
|---|---|
lowerKey(k) | Greatest key < k |
floorKey(k) | Greatest key ≤ k |
ceilingKey(k) | Smallest key ≥ k |
higherKey(k) | Smallest key > k |
TreeMap — designed for range queries & closest-matchvalues[ordinal] → no hashing, true O(1)== instead of equals(). Use for object graphs, serialization frameworks.Comparable<T> and defines compareTo(T obj)curr - param = ascendingComparator<T>, override compare(a, b)Collections.sort() or list.sort()Iterable (java.lang) → foreach, iterator()Iterator<T> it = list.iterator();hasNext() · next() · remove()modCount vs expectedModCount → ConcurrentModificationException on mismatchremove() syncs expectedModCount so it's safeiterator.remove() — not list.remove()list.removeIf(i → i == 2)Iterator.hasNext() next() nextIndex()hasPrevious() previous() previousIndex()| Property | Fail-Fast | Fail-Safe |
|---|---|---|
| CME thrown | ✓ Yes | ✗ No |
| Works on | Original collection | Clone/snapshot |
| Reflects changes | ✓ | ✗ |
| Overhead | Low | Copy overhead |
| Example | ArrayList | CopyOnWriteArrayList |
| Interface | Extends | Implemented by |
|---|---|---|
SequencedCollection | Collection | List, Deque, SequencedSet |
SequencedSet | Set + SequencedCollection | SortedSet, LinkedHashSet |
SequencedMap | Map | LinkedHashMap, TreeMap |
addFirst()addLast()getFirst()getLast()removeFirst()removeLast()reversed()firstEntry()lastEntry()pollFirstEntry()pollLastEntry()putFirst()putLast()ConcurrentNavigableMap + Serializable| Param | Default | Effect |
|---|---|---|
| initialCapacity | 16 | Initial array size |
| loadFactor | 0.75 | Resize threshold |
| concurrencyLevel | 16 | Expected concurrent writers |
size > capacity × loadFactorsize() is O(n) — sums counters across segmentsHashTable: every op locks whole table → slowsynchronizedMap: global lock → no true parallelismget(). Fail-safe iterators (work on snapshot)ArrayBlockingQueue — bounded, array-backedLinkedBlockingQueue — optionally bounded, linkedPriorityBlockingQueue — unbounded, priority-ordered| Structure | Strategy | Performance |
|---|---|---|
Vector | Method-level sync | Very slow |
synchronizedList | Global lock | Slow |
CopyOnWriteArrayList | Copy-on-write | Fast reads |
ConcurrentHashMap | Segment lock | Fast |
HashTable | Table-level lock | Slow |