Java Streams - IntStream peek(IntConsumer action) example








IntStream peek(IntConsumer action) returns a stream consisting of the elements of this stream, performing the provided action.

Syntax

peek has the following syntax.

IntStream peek(IntConsumer action)

Example

The following example shows how to use peek.

import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.rangeClosed(1,7);
    i.peek(System.out::println); 
    
  }
}