Functional Interfaces: Supplier

Provides object values.

Overview

Example

Generate Stream of random numbers using Stream.generate(Supplier):

Stream.generate(Math::random)      // Stream of random values.
    .limit(100)                    // Take only the first 100 values.
    .forEach(System.out::println); // Print each value.

This example uses a Supplier<Double>, implemented as a lambda (expressed in method reference syntax), to generate a Stream<Double> of random values. The stream is truncated after 100 items, and then each item is printed via a Consumer<Double> lambda, expressed with method reference syntax.