Streams: Advanced Concepts
In Chapter 15, we learned about the fundamentals of streams. We started by discussing what a stream pipeline is by using an analogy of an assembly line. We saw that items only make their way onto the assembly line as and when needed. This is the principle of lazy evaluation. In this analogy, there are several operators that operate on the data (pencils) under the supervision of a supervisor (Java). The supervisor will not allow any work to start until the terminal operation in place. As Java is now aware of the full pipeline, efficiencies can be introduced. Once a pencil has passed an operator, the operator cannot get that pencil back. Thus, streams are different to arrays or Collection
s in that manner. The pencils can be processed by as many operators as necessary but only one operator is the terminal operation. The other operators represent intermediate operations (a topic in this chapter).
We examined how to create streams. Streams can be created from...