UTIL PACKAGE / CATATAN</>↗Util Package29 Okt 2025
To use Map.Entry.comparingByValue for sorting a Map, you can leverage Java Streams, which provide an efficient way to process and sort collection data. Here’s how the process works: Retrieve the entrySet of the Map: This gives a set of Map.Entry objects that you can operate on with a stream. Sort using Map.Entry.comparingByValue: Use Stream.sorted() along […]
UTIL PACKAGE / CATATAN</>↗Util Package29 Okt 2025
In Java’s Stream API, Collectors.mapping is a collector that applies a mapping function to the input elements before collecting the results. It is often used as part of nested transformations, where one wants to apply a specific transformation on elements that are part of a more complex collector, such as a groupingBy. Syntax of Collectors.mapping […]
JAVA 17 / CATATAN</>↗Java 1728 Okt 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 / CATATAN</>↗Java 1128 Okt 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 / CATATAN</>↗Basic27 Okt 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 / CATATAN</>↗Util Package26 Okt 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 […]