Generate constant values from IntStream

Description

The following code shows how to generate constant values from IntStream.

Example


import java.util.stream.IntStream;
//  w w w.ja  v a 2  s .  c o  m
public class Main {

  public static void main(String[] args) {

    // stream of 1s with Stream.generate
    IntStream.generate(() -> 1)
             .limit(5)
             .forEach(System.out::println);
  }

}

The code above generates the following result.





















Home »
  Java Streams »
    Examples »




Average
Filter
Group
IntStream
Map
Partition
Reduce
Sort
Sum