Java 8

Duration Example Java 8

The Duration (java.time.Duration package) is the amount of time between two Instant’s, between two LocalDateTime or between two LocalTime . Using Duration we measures time in seconds and nanoseconds. Let see Duration examples to find out difference in seconds 1) Creating Duration Using Instant Example:

Output:

2) Creating Duration Using LocalDateTime Example:

Output:

Duration Example Java 8Read More »

Example Converting String to LocalDateTime to LocalDate or LocalTime or Timestamp

LocalDateTime is an immutable date-time object that represents a date-time, with default format as yyyy-MM-dd-HH-mm-ss.nnn. We will see in below post how to convert String to LocalDateTime, LocalDateTime to LocalDate, LocalDateTime to LocalTime or LocalDateTime to java.sql.Timestamp Example 1) Convert String to LocalDateTime: For converting String to LocalDateTime, LocalDateTime class provides a static parse() method that takes string input arguments to …

Example Converting String to LocalDateTime to LocalDate or LocalTime or TimestampRead More »

Java 8 Stream – Reading CSV file line by line

In previous example, we see reading text file line by line using Files.lines method as Stream. In this tutorial we will see reading csv file. We have sample file FlightDetail.csv containing flight number, flight name, departure airport and airport city details line by line in CSV (comma separated values) file.

1. Reading CSV File …

Java 8 Stream – Reading CSV file line by lineRead More »

Java 8 Stream – Reading text file line by line

In Java 8, we can use Files.lines to read text (or csv file etc ) file as Stream. Suppose we have sample file FlightDetail.txt containing flight number, flight name, departure airport and airport city details line by line.

1. Reading Text File Using Java 8 Stream

Output:

2. Read Text File + …

Java 8 Stream – Reading text file line by lineRead More »