LongStream forEachOrdered(LongConsumer action) example

Description

LongStream forEachOrdered(LongConsumer action) performs an action for each element of this stream, and each element is processed in encounter order. This is a terminal operation.

Syntax

forEachOrdered has the following syntax.


void forEachOrdered(LongConsumer action)

Example

The following example shows how to use forEachOrdered.


import java.util.stream.LongStream;
//from  w  ww.j  a va 2  s  .  co m
public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);

    b.forEachOrdered(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