Stream's generate method
returns aninfinite sequential stream
where supplier generates each element.- Following are the primitive Specializations for Supplier interface in
java.util.function
package.IntSupplier
– Represents a supplier ofint
-valued results. Having one methodgetAsInt()
.LongSupplier
– Represents a supplier oflong
-valued results. Having one methodgetAsLong()
.DoubleSupplier
– Represents a supplier ofdouble
-valued results. Having one methodgetAsDouble()
.BooleanSupplier
– Represents a supplier ofboolean
-valued results. Having one methodgetAsBoolean()
.
Syntax :
- Let’s say you want to generate 5 random numbers between 0 to 10.
Stream's generate method
returns aninfinite sequential stream
where supplier generates each element.
Example :
Example: Returns a supplier
Example: Factory