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);
  }//w  w  w  . j  av a2s  . c o  m
}

Result

Related Topic