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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.