Chapter 5. Working with streams

This chapter covers

  • Filtering, slicing, and mapping
  • Finding, matching, and reducing
  • Using numeric streams (primitive stream specializations)
  • Creating streams from multiple sources
  • Infinite streams

In the previous chapter, you saw that streams let you move from external iteration to internal iteration. Instead of writing code, as follows, where you explicitly manage the iteration over a collection of data (external iteration),

List<Dish> vegetarianDishes = new ArrayList<>();
for(Dish d: menu) {
    if(d.isVegetarian()){
        vegetarianDishes.add(d);
    }
}

you can use the Streams API (internal iteration), which supports the filter and collect operations, to manage the iteration over the collection of data for you. All ...

Get Modern Java in Action 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.