Loading…
Loading…
Topic
Articles and problems tagged Java Collections.
Concurrent collections and threading problems for the OCP 21 exam: ConcurrentHashMap, CopyOnWriteArrayList, skip-list and blocking queue classes, synchronized wrappers, ConcurrentModificationException, then deadlock, starvation, livelock and race conditions with fixes.
Java 21 sequenced collections for the OCP exam: getFirst, addLast, removeFirst and reversed on SequencedCollection, SequencedSet and SequencedMap methods, sequenced versus sorted, which classes qualify, unmodifiable views, and a review table of every collection type.
Sorting for the OCP 21 exam: writing compareTo with Comparable, building Comparator objects with lambdas, comparing, thenComparing and reversed, Collections.sort versus List.sort, binarySearch return values, and why TreeSet fails at run time without an order.
Maps for the OCP 21 exam: HashMap, LinkedHashMap and TreeMap ordering, Map.of, ofEntries and copyOf, get, getOrDefault, put, putIfAbsent, replace, replaceAll, forEach and entrySet, plus the exact null rules of merge, compute, computeIfAbsent and computeIfPresent.
Sets, queues and deques for the OCP 21 exam: HashSet, LinkedHashSet and TreeSet ordering, Set.of and Set.copyOf, null and Comparable rules, Queue methods that throw versus return null, Deque methods at both ends, stacks with push, pop and peek, and ArrayDeque versus LinkedList.
Lists for the OCP 21 exam: ArrayList versus LinkedList, Arrays.asList, List.of and List.copyOf, constructors, index-based methods, replaceAll, the overloaded remove trap, indexOf and lastIndexOf, IndexOutOfBoundsException, and converting lists to arrays.
The Java Collections Framework for the OCP 21 exam: List, Set, Queue, Deque and Map, generics with the diamond operator and var, and the Collection methods add, remove, size, isEmpty, clear, contains, removeIf, forEach, iterators, equals and unboxing pitfalls.
Scope and object lifetime for the OCP Java 21 exam: block scope for locals, parameters, loop variables, fields and static variables, shadowing and redeclaration rules, when objects become eligible for garbage collection, System.gc(), and why finalize() is obsolete.
Java 1.0's legacy collections and what to use today: Hashtable vs HashMap, Enumeration and how to convert it, Properties files with defaults and UTF-8, system properties, why Stack lost to ArrayDeque, and BitSet with a sieve of Eratosthenes example.
The algorithms in java.util.Collections and Arrays: stable sorting with comparators, shuffling, binary search and insertion points, min, max, reverse, rotate, removeIf and replaceAll, set operations with retainAll and removeAll, toArray, and writing your own generic algorithms.
List.of, Set.of, Map.of and copyOf versus Collections.unmodifiableList, Arrays.asList, subList and range views, reversed views, newSetFromMap, and checked and synchronized wrappers. Learn which give independent copies and which give live windows, plus the null and ordering pitfalls.
Master Java map views (keySet, values, entrySet) and Map.Entry, then the specialized maps and sets: LinkedHashMap with access order and an LRU cache, SequencedMap, EnumSet and EnumMap, IdentityHashMap, and WeakHashMap with its garbage-collector tricks.
A practical guide to Java's Map interface: HashMap versus TreeMap, put, get and getOrDefault, iterating with forEach, and updating entries the modern way with merge, compute, computeIfAbsent and putIfAbsent. Includes word counting, multimaps, and the null-value pitfalls.
Learn Java's Queue, Deque and PriorityQueue: offer/poll/peek versus add/remove/element, ArrayDeque as a fast queue and stack, Java 21 sequenced methods, and how a binary heap gives a priority queue O(log n) add and remove, with job scheduling and top-k examples.
How Java's HashSet and TreeSet work: hash codes, buckets, collisions, load factor and rehashing, HashSet.newHashSet, the danger of mutating set elements, red-black tree sorted sets, comparators that disagree with equals, and NavigableSet methods like floor, ceiling and headSet.
How Java's LinkedList and ArrayList work inside, when each one wins, and how to use ListIterator to add, set and remove while you walk a list. Covers fail-fast iterators, ConcurrentModificationException, the get(i) loop trap, and why Vector is obsolete.
A tour of the Java collection interfaces: Collection versus Map, List with random access and the remove(int) trap, Set equality, SortedSet and NavigableSet, the Java 21 SequencedCollection, SequencedSet and SequencedMap, RandomAccess, and an overview of all concrete collection classes.
Start the Java Collections Framework: why interfaces are separate from implementations, the Collection and Iterable interfaces, how iterators work between elements, next, hasNext and remove, forEach, bulk operations, and building your own collection with AbstractCollection.
Use Java's ArrayList, the resizable array: declaring ArrayList<Employee> with var and the diamond operator, add, get, set, insert and remove, size versus capacity, ensureCapacity and trimToSize, for-each loops, converting to arrays, Java 21 getFirst/getLast, and raw-type compatibility.
Update a Java ConcurrentHashMap atomically with compute, merge and computeIfAbsent, run parallel search, forEach and reduce bulk operations, build concurrent sets, use copy-on-write lists, parallelSort, parallelSetAll and parallelPrefix, and compare synchronization wrappers.