Useful documentation:
https://www.w3schools.com/java/java_lambda.asp
https://stackify.com/streams-guide-java-8/
-
Have a look at ExampleLambdas. Design a simple meaningful application that contains at least one functional interface. Implement these interface(s) by using lambda expressions.
-
Run the examples from ExampleStreams. Implement the two methods that are not yet implemented. Implement the unit tests for the methods 1 to 8 in ExampleStreamsTest.
Implement the code and unit tests for the following exercises:
-
Given a list of strings, write a Java program to find the length of the longest string using the Java Stream API.
-
Find the sum of all even numbers in a list of integers.
-
Convert a list of strings to uppercase.
-
Group a list of words by their first letter.
-
Count the number of occurrences of a word in a text file. This program should read in a text file and count the number of times a given word appears in the file. It should use the Stream API to read in the file and count the occurrences of the word using a lambda function. (hint: you can use Files.lines() / Files.readAllLines() - what's the difference between the two?)
-
Suppose we have a class called Product that has the fields name, price, and category. We want to filter a list of Product objects to include only those that are in the "Electronics" category, and then sort them by price. (use method sorted() from Stream API)
-
Suppose we have a class called Order that has the fields id, total, and status. We want to calculate the total revenue of all completed orders. (use method reduce() from Stream API)