Java 8 Streams Java Java API
Interface:
java.util.stream.IntStream
Method:
IntStream peek(IntConsumer action)
This intermediate operation returns an IntStream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.
Examples
package com.logicbig.example.intstream;
import java.util.stream.IntStream;
public class PeekExample {
public static void main(String... args) { IntStream intStream = IntStream.range(1, 5); int sum = intStream.peek(System.out::println) .sum(); System.out.println(sum); } }
Output1 2 3 4 10
|