JAVA 17 / NOTES</>↗Java 1728 Oct 2025
The Collectors.partitioningBy is a method in Java’s java.util.stream.Collectors class that is used to partition elements of a stream into two groups based on a predicate. It essentially creates a Map with a boolean key (true or false) and lists of elements as values. Here’s an explanation of how to use it effectively: Syntax: Collectors.partitioningBy(Predicate<? super […]
JAVA 11 / NOTES</>↗Java 1128 Oct 2025
In Java, you can use the Stream API’s Collectors to gather stream results into an immutable collection. Since Java 10, you can use Collectors.toUnmodifiableList(), Collectors.toUnmodifiableSet(), and other similar methods to collect the results into unmodifiable collections. Here’s how you can collect the stream results into an immutable collection: 1. Immutable List To collect the results […]
BASIC / NOTES</>↗Basic27 Oct 2025
The Map.merge method in Java is a convenient way to simplify various kinds of logic that require updating or modifying values in a map, such as counting occurrences. It works by letting you specify how to combine the old value (if it exists) and the new value (to be added). This is particularly useful for […]
UTIL PACKAGE / NOTES</>↗Util Package26 Oct 2025
To safely use ConcurrentHashMap.computeIfAbsent, it’s important to understand both its purpose and how to use it in a thread-safe manner. Purpose of computeIfAbsent computeIfAbsent is a method of ConcurrentHashMap that: Checks if the key exists in the map. If the key exists, it returns the associated value. If the key does not exist, it computes […]
JAVA 16 / NOTES</>↗Java 1626 Oct 2025
In Java, a LinkedHashMap is a subtype of HashMap that maintains a predictable iteration order. It uses a doubly linked list to store the entries in insertion order (or, optionally, access order). Here’s how you can use LinkedHashMap for predictable iteration order: 1. Maintaining Insertion Order By default, a LinkedHashMap iterates its entries in the […]
SOUND API / NOTES</>↗Sound API25 Oct 2025
The Collectors.groupingBy is a powerful method in Java’s Stream API that allows grouping of elements in a stream based on a classification function, and it works well with downstream collectors. Here’s how you can use Collectors.groupingBy with downstream collectors effectively. Syntax of Collectors.groupingBy with a Downstream Collector The key method signature is: Collectors.groupingBy(Classifier, Downstream) Classifier: […]