Collectors.mapping: practical reference
Collectors.mapping: practical reference: Collectors.mapping applies a mapping function to each input and forwards the mapped values to a downstream collector.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Collectors.mapping: practical reference: Collectors.mapping applies a mapping function to each input and forwards the mapped values to a downstream collector.
Collectors.partitioningBy: practical reference: Collectors.partitioningBy divides input into exactly two Boolean-keyed groups according to a predicate, with an optional downstream collector.
Get the count, sum, minimum, maximum, and average in one pass over an object stream by specifying how to obtain a double from each element.
Collectors.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.
Collectors.toMap: practical reference: Collectors.toMap creates a Map from key and value mapping functions; overloads control duplicate-key merging and the concrete map supplier.
Collectors.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.
Compare 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.
Build 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.
Create a comparator that orders objects by an ascending `int` key without boxing the key as an `Integer`.
Sort 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.
Use `Comparator.naturalOrder()` to sort by the type’s own order: case-sensitive lexicographic order for `String` and numeric order for `Integer`.
Use `Comparator.nullsFirst` to put missing ages before known ages among records that tie on the primary sort key.
Place `null` after all non-null values for a given sort key, such as when ordering people by last name and then by first name.
`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.
Combine sorting criteria so that the next criterion is used only when the earlier ones cannot decide the order of a pair.
Add an ascending `int` key to an existing comparator. The numeric key determines the order only when the existing comparator returns `0`.
Comparator.thenComparingLong adds an ascending long key, used only when the preceding comparator reports a tie.
Compose stages in Java SE 21, recover from failures, coordinate multiple futures, and explicitly choose executors for asynchronous work.
Use `get()` to retrieve a result or `get(timeout, unit)` to limit the wait. Unlike `join()`, both overloads declare checked exceptions.
`join()` retrieves a `CompletableFuture` result, waiting for completion if necessary. It declares no checked exceptions, but it can still throw an unchecked exception.
Pass a custom `Executor` to choose how the task runs. A direct executor such as `Runnable::run` runs the task immediately on the calling thread instead of using the common pool.
Use `thenApply` to transform a stage’s result after it completes normally. It returns a new stage and does not guarantee that the function runs on a separate thread.
`thenCombine` creates a new `CompletableFuture` whose value is computed only after both input stages complete normally, for example to add the counts from two independent operations.
CompletionException is an unchecked exception signaling a failure while completing a task or result. With CompletableFuture, it carries the underlying failure to code retrieving the result through join().