Java Stream How to - Create Supplier Lambda and call get method








Question

We would like to know how to create Supplier Lambda and call get method.

Answer

import java.util.function.Supplier;
/*from   ww  w.  j av  a 2 s  .  c  o m*/
public class Main {

  public static void main(String[] args) {
    Supplier<Integer> rndRange = () -> (int) (Math.random() * 100);
    System.out.println(rndRange.get());
  }

}

The code above generates the following result.