JAVA 8 / CATATAN</>↗Java 824 Jan 2024
The List.replaceAll() method was introduced in Java 8. This method replaces each element of the list with the result of applying the operator to that element. The operator or function you pass to replaceAll() should be a UnaryOperator. Here is a simple example: package org.kodejava.util; import java.util.ArrayList; import java.util.List; import java.util.function.UnaryOperator; public class ListReplaceAllExample { […]
JAVA 8 / CATATAN</>↗Java 824 Jan 2024
The Collection.removeIf() method was introduced in Java 8, and it allows for the removal of items from a collection using a condition defined in a lambda expression. The primary purpose of the Collection.removeIf() method in Java is to filter out elements from a collection based on a certain condition or predicate. It’s a more efficient […]
LANG PACKAGE / CATATAN</>↗Lang Package24 Jan 2024
The purpose of the String.strip() method in Java 11 is to remove whitespaces from both the beginning and end of a string. This is very similar to the String.trim() method available in earlier versions of Java, but there is a key difference between them. Here’s the difference: String.strip(): Introduced in Java 11, strip() uses the […]
JAVA 9 / CATATAN</>↗Java 924 Jan 2024
In Java, the Map.of() factory method can be used to create an unmodifiable map of specified key-value pairs. This method is available in Java 9 and later versions. Creating a map is a bit more complicated than creating lists or sets. Because we need to provide keys and values when creating a map. When using […]
JAVA 9 / CATATAN</>↗Java 924 Jan 2024
As with List.of(), in Java 9, the Set.of() factory method can be used to create an unmodifiable set of specified elements. Here is a simple example: package org.kodejava.util; import java.util.Set; public class SetOfExample { public static void main(String[] args) { Set<String> names = Set.of("Rosa", "John", "Mary", "Alice"); for (String name : names) { System.out.println(name); } […]
JAVA 9 / CATATAN</>↗Java 924 Jan 2024
In Java, you can use the List.of() factory method to create an unmodifiable List consisting of specified elements. This method is available from Java 9 onwards. Here is a simple example: package org.kodejava.util; import java.util.List; public class ListOfExample { public static void main(String[] args) { List<String> names = List.of("Rosa", "John", "Mary", "Alice"); for (String name […]