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 Using Java 8 Stream

Output:

2. Read CSV File + Perform Extra Operation + Java 8 Stream

In this example will see using Stream to filter content on the basis of some business requirement like first selecting only airlines having flight numbers BA-731 or VA-421 and then mapping filtered result to airport names only and finally returning result as a List.

Output:

Check References:

Leave a Reply

Your email address will not be published. Required fields are marked *