Java - Use nextInt() method from Random class as the Supplier in the generate() method

Description

Use nextInt() method from Random class as the Supplier in the generate() method

Demo

import java.util.Random;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    // Print five random integers
    Stream.generate(new Random()::nextInt).limit(5).forEach(System.out::println);
  }/*from  ww w .j ava 2 s .  c o m*/
}

Result

Related Topic