Pipelines and Streams

//The following example prints the male members contained in the
//collection roster with a pipeline that consists of the aggregate 
//operations filter and forEach:

roster
    .stream()
    .filter(e -> e.getGender() == Person.Sex.MALE)
    .forEach(e -> System.out.println(e.getName()));
//The following example calculates the average age of all male members 
//contained in the collection roster with a pipeline that consists of the 
//aggregate operations filter, mapToInt, and average:

double average = roster
    .stream()
    .filter(p -> p.getGender() == Person.Sex.MALE)
    .mapToInt(Person::getAge)
    .average()
    .getAsDouble();

A pipeline is a sequence of aggregate operations.

A pipeline contains the following components: a source, zero or more intermediate operations, a terminal operation.

Pipelines and Streams — Structure map

Clickable & Draggable!

Pipelines and Streams — Related pages: