This project is a simple Java application that explores the functionalities of the Java Stream API.
-
Filtering and Collecting: The application demonstrates how to filter a list of integers to get only the even numbers, both with a traditional for loop and with the Stream API.
-
Finding Elements: It shows how to find a specific element in a list of strings using the Stream API.
-
Mapping and Collecting: The application creates a list of
Fruit
objects, each with a name, category, and price. It then uses the Stream API to create a new list containing only the prices of the fruits. -
Mapping and Discounting: It demonstrates how to apply a function to each element in a stream to create a new stream. In this case, it applies a 20% discount to the price of each fruit.
-
Skipping and Limiting: The application shows how to use the
skip
andlimit
operations to manipulate the size of the stream. -
Sorting: Finally, it sorts the list of fruits in order from highest to lowest price.
To run the code, simply execute the Main
class. The results of each operation will be printed to the console.
This project provides a clear and concise introduction to the Java Stream API, demonstrating its power and flexibility for manipulating collections of data. It serves as a great starting point for anyone looking to understand and utilize this feature of Java.