Java Stream How to - Generate constant values from IntStream








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

Example

import java.util.stream.IntStream;
//w  w w  .  j  a va 2 s . co 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.