LongStream peek(LongConsumer action) example

Description

LongStream peek(LongConsumer action) returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.

Syntax

peek has the following syntax.


LongStream peek(LongConsumer action)

Example

The following example shows how to use peek.


import java.util.stream.LongStream;
//from   www.ja  v a  2s .c om
public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);

    b.forEach(System.out::println);
  }
}

The code above generates the following result.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder