A stream in Java is a sequence of elements that can be processed (mapped, filtered, transformed, reduced, and collected) in a pipeline of declarative operations using lambda expressions in a sequential or parallel way. It was introduced in Java 8 and was one of the most significant new features of that version, together with lambda expressions. They have changed the way you can process big sets of elements in Java, optimizing the way the language processes those elements.
Streams have introduced the Stream, DoubleStream, IntStream and LongStream interfaces, some utility classes such as Collectors or StreamSupport, some functional-like interfaces such as Collector, and a lot of methods in different classes such as the stream() or parallelStream() methods in the Collection interface or the lines() method in the Files class.
Through the recipes of this chapter, you will learn how to effectively use streams...