Skip to content

isp-cluj/isp-lab-11-2023

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambdas and Stream API. Solve the following exercises:

Useful documentation:
https://www.w3schools.com/java/java_lambda.asp
https://stackify.com/streams-guide-java-8/

  1. 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.

  2. 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:

  1. Given a list of strings, write a Java program to find the length of the longest string using the Java Stream API.

  2. Find the sum of all even numbers in a list of integers.

  3. Convert a list of strings to uppercase.

  4. Group a list of words by their first letter.

  5. 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?)

  6. 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)

  7. 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)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages