Pick the Collection:Nulls, Order, Threads, and the Hot Operation
A decision guide for the Java Collections series: given the hot operation, null policy, encounter order, and whether another thread looks — which JDK type to new.
Read More30 post(s)
A decision guide for the Java Collections series: given the hot operation, null policy, encounter order, and whether another thread looks — which JDK type to new.
Read MoreLearn how Java 21 sequenced collections provide uniform first, last, and reversed operations across lists, deques, ordered sets, and ordered maps.
Read MoreWhat Java Stream Gatherers are (JEP 485 / Java 24), why map/filter/flatMap hit a wall, built-ins like windowFixed and fold, and how to write a short custom gatherer.
Read MoreA beginner-to-intermediate guide to Java Streams: source → filter/map/flatMap → collect, lazy pipelines, and when a plain for loop is clearer.
Read MoreUse Collection.stream, parallelStream, spliterator characteristics, and Collectors.toCollection to leave a collection and land in the right one — without re-teaching Stream.map.
Read MoreUse ConcurrentLinkedQueue and ConcurrentLinkedDeque for non-blocking ends, and ConcurrentSkipListMap/Set when you need a concurrent sorted map — not a BlockingQueue and not a HashMap.
Read MoreUse BlockingQueue to pass work between threads — put/take that block, offer/poll with timeouts, and when to pick Array, Linked, Delay, Synchronous, or Transfer queues.
Read MoreUse CopyOnWriteArrayList and CopyOnWriteArraySet when iteration is the hot path — every mutation copies the array, and iterators walk a snapshot.
Read MoreUse ConcurrentHashMap for a shared map — per-bin concurrency, no nulls, weakly consistent iterators, and atomic compute/merge — not Hashtable and not synchronizedMap.
Read MoreRecognize Vector, Stack, Hashtable, Dictionary, Enumeration, and Properties as legacy — synchronized whole-table types you should not choose for new code.
Read MoreUse Collections and Arrays for sort, binarySearch, shuffle, nCopies, emptyXxx, synchronized wrappers, and asList — the static methods around the types, not a fourth List implementation.
Read MoreUse List.of, Set.of, Map.of, and copyOf for unmodifiable collections that reject nulls — Java 9 factories, not Collections.unmodifiableList wrapping a live ArrayList.
Read MoreUse IdentityHashMap when keys are compared with ==, and WeakHashMap when the GC should drop entries whose keys are otherwise unreachable — two unusual maps, two different jobs.
Read MoreUse EnumSet and EnumMap when the key universe is an enum — a bit vector and an ordinal array, not a hash table.
Read MoreA decision guide for the data-structures series: given the hot operation, which layout and which JDK type — with links to every post in the series.
Read MoreUse TreeSet and TreeMap when keys must stay sorted — O(log n) red-black trees, Navigable ceiling/floor, and a Comparator that stays consistent with equals.
Read MoreUse PriorityQueue when you need the next-best element in O(log n) — a heap, not a sorted list, and not a FIFO queue.
Read MoreUse LinkedHashMap when a hash map must iterate in insertion order — or access order with removeEldestEntry for a bounded LRU.
Read MoreUse LinkedList only when you need List and Deque on the same nodes — and why it usually loses to ArrayList for indexes and ArrayDeque for ends.
Read MoreUse ArrayDeque as the default deque — a resizable ring buffer for stack and queue work without Vector, Stack, or LinkedList.
Read MoreUse HashMap as the default Map — hash spreading, buckets, treeify, resize, and why a mutable key makes an entry disappear.
Read MoreUse HashSet for uniqueness and LinkedHashSet when uniqueness still needs insertion order — both are HashMap wrappers, and neither is a sorted set.
Read MoreUse ArrayList as the default List — amortized append, O(1) get, ensureCapacity, and the fail-fast iterator — and know when growth copies the whole array.
Read MoreUse Map as mappings, not a Collection — get/put, compute and merge, and the keySet/values/entrySet views that write through to the same storage.
Read MoreUse Queue and Deque when the job is the ends — offer/poll versus add/remove, exception versus special value, and why indexes are the wrong primitive.
Read MoreUse Set when uniqueness is the job — equals-based membership, no indexes, and why List.contains is the wrong uniqueness type.
Read MoreUse List as an indexed contract — get/set, subList views, sort/replaceAll, and RandomAccess — without treating every List like an ArrayList.
Read MoreUse Collection and Iterator as the shared contract — optional operations, fail-fast iteration, bulk methods, and removeIf — before you pick ArrayList or HashSet.
Read MoreThe Java Collections Framework as a map: hierarchy, glossary, a nulls-order-threads matrix, and a living catalog of every post in this series.
Read MoreA beginner-to-advanced path through data structures: glossary, Big-O literacy, a JDK map, and a living index of every post in this series.
Read More