JAVA / CATATAN{ }↗Java20 Okt 2025
In Java, Collectors::teeing is a feature introduced in Java 12 that allows you to collect elements of a stream using two different collectors and then combine the results using a BiFunction. Syntax: static <T, R1, R2, R> Collector<T, ?, R> teeing(Collector<? super T, ?, R1> downstream1, Collector<? super T, ?, R2> downstream2, BiFunction<? super R1, […]
JAVA / CATATAN{ }↗Java19 Okt 2025
The List.of, Set.of, and Map.of factory methods were introduced in Java 9 to create immutable collections in a simpler and more concise way. These methods directly create unmodifiable instances of List, Set, or Map. Usage of List.of The List.of method is used to create an unmodifiable List containing the provided elements. The key characteristics are: […]
JAVA / CATATAN{ }↗Java19 Okt 2025
The RandomGenerator API, introduced in JDK 17, provides a simpler and more flexible way to work with random number generation by centralizing the different strategies for producing random numbers under a single interface (RandomGenerator). This allows developers to access multiple random number generation algorithms in a standardized manner. Additionally, it improves upon the legacy java.util.Random […]
JAVA / CATATAN{ }↗Java18 Okt 2025
Using records with generics in Java allows you to create immutable data structures while also providing the benefits of generics, such as type safety and flexibility. Since Java 16, the record feature was introduced, and it can be combined with generics like other classes. Here’s an example of how to use records with generics. Syntax […]
JAVA / CATATAN{ }↗Java18 Okt 2025
The String class in Java provides the methods strip(), isBlank(), and lines(), which were introduced in Java 11. These methods are useful for managing whitespaces, checking for blank strings, and processing multi-line strings. 1. strip() The strip() method removes leading and trailing whitespaces from a string. Unlike trim(), it uses Unicode-aware whitespace handling, making it […]
JAVA / CATATAN{ }↗Java17 Okt 2025
Compact constructors in records are a concise way to initialize and validate fields of a record in Java. Unlike standard constructors, compact constructors omit the parameter list, as they operate directly on the record’s declared components. Here’s how to use compact constructors in records: 1. Syntax: A compact constructor is declared without parentheses after the […]