LongStream forEach(LongConsumer action) example

Description

LongStream forEach(LongConsumer action) performs an action for each element of this stream. This is a terminal operation.

Syntax

forEach has the following syntax.


void forEach(LongConsumer action)

Example

The following example shows how to use forEach.


import java.util.stream.LongStream;
//w ww.  j av  a 2 s  . 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