Using streams in collections
Processing all data elements in a collection is a common action. Maybe you want to extract a subset of the collection based on a specific requirement. You might want to increase or decrease values or change the case of strings. This is where streams come in. All classes that implement the Collection
interface have a stream method from which we can chain numerous stream methods. You cannot use streams directly on maps, but if you convert a map into a set, then you can use streams.
One important characteristic of stream methods is that they operate as pure functions. A pure function does not change the state of any fields in the class or any of the parameters passed to it. A stream method always returns a new stream. The original stream has not changed. Let’s see how this works:
public record Employee(String employeeId, String firstName, String lastName, String department, double salary)...