JAVA 8 / CATATAN</>↗Java 817 Jan 2024
In the Java Date-Time API, the plus and minus methods can be used to calculate and modify dates, times, date/times, and durations. Each temporal class (LocalDate, LocalTime, LocalDateTime, and Duration) includes these methods. Here’s a basic example using the LocalDate class: package org.kodejava.datetime; import java.time.LocalDate; public class PlusMinusExample { public static void main(String[] args) { […]
JAVA 8 / CATATAN</>↗Java 815 Jan 2024
The atDate() method is a part of LocalTime class in the Java Date-Time API. This method combines this time with a date to create an instance of LocalDateTime. Here’s an example: package org.kodejava.datetime; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; public class AtDateExample { public static void main(String[] args) { // Create a LocalTime instance LocalTime […]
JAVA DATE TIME API / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]