Using the Stream class methods

In this section, we will explore how the Stream class methods are used to solve various types of problems. Streams are useful for transforming stream elements, filtering elements, and reducing elements. They can mimic SQL-type processing and implement the map-reduce paradigm, which we will illustrate in the Implementing the map-reduce paradigm section.

Filter methods

The process of filtering involves iterating over a sequence and eliminating those elements that are no longer needed. We will examine how this is accomplished using an imperative loop and then how it is performed using streams.

Assume that we want to filter out the plural names in an animal list. We start with an array of strings containing animal names. ...

Get Learning Java Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.