Java Stream How to - Generate int from IntSupplier for IntStream








The following code shows how to generate int from IntSupplier for IntStream.

Example

/*  w w w.  j  a  v a 2  s.c  o  m*/
import java.util.function.IntSupplier;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    IntStream.generate(new IntSupplier(){
      public int getAsInt(){
          return 2;
      }
     }).limit(5)
       .forEach(System.out::println);
  }

}

The code above generates the following result.