Skip to Main Content
Java 8 in Action
book

Java 8 in Action

by Mario Fusco, Alan Mycroft, Raoul-Gabriel Urma
August 2014
Intermediate to advanced content levelIntermediate to advanced
424 pages
13h 50m
English
Manning Publications
Content preview from Java 8 in Action

Chapter 5. Working with streams

This chapter covers

  • Filtering, slicing, and matching
  • Finding, matching, and reducing
  • Using numeric streams such as ranges of numbers
  • 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 you need ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java 8 Lambdas and Streams

Java 8 Lambdas and Streams

Madhusudhan Konda
Modern Java in Action

Modern Java in Action

Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft
Java 8 Lambdas

Java 8 Lambdas

Richard Warburton

Publisher Resources

ISBN: 9781617291999Supplemental ContentPublisher SupportOtherPublisher WebsiteErrata PageSupplemental ContentPurchase Link