Lesson 35Working with Lambdas and Streams

Streams, in conjunction with lambdas, allow developers to process data from Collections in a powerful way. In this lesson, we will cover a lot of terminology and look at these features to see how we can use them to simplify our code and make it more efficient.

USING AGGREGATE OPERATIONS

When we use Collections to store objects in our programs, we generally need to do more than simply put the objects in the Collection: we also need to store, retrieve, remove, and update these objects.

Aggregate operations use lambdas to perform actions on the objects in a Collection. For example, you can use aggregate operations to:

  • Print the names of all the people in a Collection of Address objects
  • Return all of the Address objects for people from Akron, Ohio
  • Return all of the Address objects for people from Akron, Ohio, grouped by ZIP code
  • Calculate and return the average age of servers in your inventory (provided the Server object has a purchase date field)

These tasks can be accomplished by using aggregate operations along with pipelines and streams.

UNDERSTANDING PIPELINES AND STREAMS

A pipeline is simply a sequence ...

Get Job Ready Java 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.