In this recipe, we will describe how streams can be created and how the operations can be applied to the elements emitted by the streams. The discussion and examples are applicable for a stream of any type, including the specialized numeric streams: IntStream, LongStream, and DoubleStream. The behavior specific to the numeric streams is not presented because it is described in the next recipe, Using numeric streams for arithmetic operations.
Creating and operating on streams
Getting ready
There are many ways to create a stream:
- The stream() and parallelStream() methods of the java.util.Collection interface—this means that all the sub-interfaces, including Set and List, have these methods too
- Two overloaded stream...