JAVA 8 / CATATAN</>↗Java 814 Jan 2024
The String.join() method in Java is a static method added in Java 8 to the java.lang.String class. The String.join() is a static utility method used to concatenate multiple strings, arrays or collections (like lists and sets) of strings. This method makes it easier to join multiple strings with a specific delimiter. A delimiter is a […]
JAVA 8 / CATATAN</>↗Java 814 Jan 2024
The java.util.Optional<T> class is a container object that may or may not contain a non-null value. It was introduced in Java 8 as part of the Java language’s growing emphasis on treating null values as an anti-pattern. Optional is a way of replacing a nullable T reference with a non-null but potentially empty Optional<T> reference. […]
JAVA 8 / CATATAN</>↗Java 814 Jan 2024
Collectors.partitioningBy() is a special case of a grouping collector in Java’s Stream API. It partitions or divides the input elements into two groups, based on the result of a Predicate function. One group for which the Predicate function returns true, and the other where it returns false. Each group is a List of elements, and […]
JAVA 8 / CATATAN</>↗Java 813 Jan 2024
In Java 8, the Collectors.groupingBy() method in the Stream API is used to group elements of the stream into a `Map“ based on a categorization function. Here’s a basic example: package org.kodejava.stream; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; public class CollectorsGroupingBy { public static void main(String[] args) { List<String> names = […]
JAVA 8 / CATATAN</>↗Java 813 Jan 2024
The Collectors.summarizingInt method is actually similar to the summaryStatistics we discussed in the previous example. It returns a special class (IntSummaryStatistics) which encapsulates a set of summary statistical values for a stream of integers. Here’s an example: package org.kodejava.stream; import java.util.Arrays; import java.util.IntSummaryStatistics; import java.util.List; import java.util.stream.Collectors; public class SummarizingIntExample { public static void ma...
JAVA 8 / CATATAN</>↗Java 813 Jan 2024
The summaryStatistics method is a handy utility in the Java Stream API that returns a special class (IntSummaryStatistics, LongSummaryStatistics, or DoubleSummaryStatistics) encapsulating a set of statistical values: the count, sum, minimum, maximum, and average of numbers in the stream. Here’s a basic example using IntSummaryStatistics: package org.kodejava.stream; import java.util.Arrays; import java.util.IntSummaryStatistics; import java.util.List; public class […]