Summary
In this chapter, we explored advanced streaming concepts. We started by exploring intermediate operations, which are powerful, as they transform the stream into another stream. Popular intermediate operations are: filter()
, distinct()
, limit()
, map()
, flatMap()
, and sorted()
. Some of these are known as stateful as they need to maintain some state to operate effectively. Examples are limit()
and sorted()
. The limit()
method is also short-circuiting as it can cause the pipeline to shut down even if there is more data available in the source.
We then examined the primitive stream types in the API, namely IntStream
, LongStream
and DoubleStream
. These types have some very useful methods for operating on numeric types, such as sum()
and average()
. We also explained the patterns behind the names of the new primitive stream functional interfaces and their functional methods.
We can create streams by mapping from another stream. There are many methods to do this but they follow...