The use of streams is considered to be one aspect of functional programming languages. In this chapter, we addressed the use of streams as supported by Java 8. We demonstrated the creation and use of finite and infinite streams. These depend on some data source, which might be bounded in length as with arrays or indefinite if derived from a source such as a network connection.
The Stream
class supports the stream concept in Java. While it possesses many methods, we covered only a few with the goal of imparting a feel for the use and power of streams. We examined the filter
, skip
, and sorted
methods and used them in several examples. We demonstrated the popular map-reduce technique, which potentially modifies a set of data and then combines these values into a result.
The concepts of lazy and eager evaluation were examined and illustrated. Lazy evaluation makes possible the use of infinite streams. You also learned that a stream execution begins when the terminal method starts and ends...