IntStream forEach(IntConsumer action) example

Description

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

Syntax

forEach has the following syntax.


void forEach(IntConsumer action)

Example

The following example shows how to use forEach.


import java.util.stream.IntStream;
/* www .  ja  va 2s . c o m*/
public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.of(1);
    i.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