JavaCollectors.collectingAndThen: practical reference: Collectors.collectingAndThen adapts a downstream collector and applies a finishing function exactly once to its completed result; the returned collector does not retain IDENTITY_FINISH.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaCollectors.counting: practical reference: Collectors.counting returns a collector equivalent to reducing every element to 1L and summing, so its result type is Long.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaCollectors.groupingBy: practical reference: Collectors.groupingBy classifies each element by a key function and accumulates a Map from keys to group results; its overloads select the map supplier and downstream collector.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJava`Collectors.groupingByConcurrent` groups stream elements by key and can count each category without preserving the order in which elements are encountered.
Advanced · Java SE 21JavaCollectors.joining: practical reference: Collectors.joining concatenates CharSequence elements, optionally inserting a delimiter and surrounding the result with a prefix and suffix.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaCollectors.mapping: practical reference: Collectors.mapping applies a mapping function to each input and forwards the mapped values to a downstream collector.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaCollectors.partitioningBy: practical reference: Collectors.partitioningBy divides input into exactly two Boolean-keyed groups according to a predicate, with an optional downstream collector.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaGet the count, sum, minimum, maximum, and average in one pass over an object stream by specifying how to obtain a double from each element.
Basic · Java SE 21JavaCollectors.toList: practical reference: Collectors.toList accumulates stream elements into a List while making no promise about the concrete list type, serializability, thread safety, or mutability.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaCollectors.toMap: practical reference: Collectors.toMap creates a Map from key and value mapping functions; overloads control duplicate-key merging and the concrete map supplier.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaCollectors.toSet: practical reference: Collectors.toSet accumulates elements into a Set and therefore removes duplicates, but it does not guarantee set type, order, mutability, serializability, or thread safety.
Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtimeJavaCompare objects by their natural order. Read the sign of the result, distinguish an ordering tie from equals, and choose which object to keep when values tie.
Basic · Java SE 21JavaBuild an object comparator from a key extractor. Use the keys’ natural order or supply a separate comparator to define their order, including where `null` keys belong.
Basic · Java SE 21JavaCreate a comparator that orders objects by an ascending `int` key without boxing the key as an `Integer`.
Basic · Java SE 21JavaSort tasks by highest priority first and break ties with the smallest sequence number. See where `reversed()` belongs and how to supply the explicit `<Task>` type argument.
Advanced · Java SE 21JavaUse `Comparator.naturalOrder()` to sort by the type’s own order: case-sensitive lexicographic order for `String` and numeric order for `Integer`.
Intermediate · Java SE 21JavaUse `Comparator.nullsFirst` to put missing ages before known ages among records that tie on the primary sort key.
Intermediate · Java SE 21JavaPlace `null` after all non-null values for a given sort key, such as when ordering people by last name and then by first name.
Intermediate · Java SE 21Java`Comparator.reversed()` returns a comparator that orders elements in the opposite direction from an existing comparator. The call itself does not sort or change a list.
Basic · Java SE 21JavaCombine sorting criteria so that the next criterion is used only when the earlier ones cannot decide the order of a pair.
Basic · Java SE 21JavaAdd an ascending `int` key to an existing comparator. The numeric key determines the order only when the existing comparator returns `0`.
Basic · Java SE 21JavaComparator.thenComparingLong adds an ascending long key, used only when the preceding comparator reports a tie.
Intermediate · Java SE 21; repository runtime, production runtime not attestedJavaCompose stages in Java SE 21, recover from failures, coordinate multiple futures, and explicitly choose executors for asynchronous work.
Advanced · Java SE 21JavaUse `get()` to retrieve a result or `get(timeout, unit)` to limit the wait. Unlike `join()`, both overloads declare checked exceptions.
Intermediate · Java SE 21