JAVA DATE TIME API / NOTES</>↗Java Date Time API15 Jan 2024
The atTime() method belongs to the LocalDate class in the Java Date-Time API, not the Date class. This method combines this date with a time to create a LocalDateTime. Here’s an example: package org.kodejava.datetime; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; public class AtTimeExample { public static void main(String[] args) { // Create a LocalDate instance […]
JAVA 8 / NOTES</>↗Java 814 Jan 2024
The map method of the Optional class in Java is used to transform the value contained in the Optional. map allows you to apply a function on the value inside the Optional and returns an Optional that contains the result of the function. Here is an example of how to use it: package org.kodejava.util; import […]
JAVA 8 / NOTES</>↗Java 814 Jan 2024
The flatMap method is a special method in the Optional class in Java, if a method returns an Optional, you can use flatMap to avoid nested Optional<Optional<T>> situations. Here is an example: package org.kodejava.util; import java.util.Optional; public class OptionalFlatMap { public static void main(String[] args) { Optional<String> nonEmptyGender = Optional.of("male"); Optional<String> emptyGender = Optional.empty(); System.out.println("Non-Empty […]
JAVA 8 / NOTES</>↗Java 814 Jan 2024
The java.util.Optional class in Java provides a filter method. It’s used to apply a condition on the value held by this Optional. Here is an example of how to use Optional‘s filter method: package org.kodejava.util; import java.util.Optional; public class OptionalFilter { public static void main(String[] args) { // Creating Optional object and assigning a value […]
JAVA 8 / NOTES</>↗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 / NOTES</>↗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. […]