Java Stream peek operation

Description

Java Stream peek operation

import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    int sum = Stream.of(1, 2, 3, 4, 5)
        .peek(e -> System.out.println("Taking integer: " + e))
        .filter(n -> n % 2 == 1)/*from w w  w.j  av a 2 s. com*/
        .reduce(0, Integer::sum);
    System.out.println("Sum = " + sum);

  }
}



PreviousNext

Related