Java streams 7. Create using Stream.generate()

The static Stream.generate(Supplier<T>) method returns Stream<T> object that emits an infinite number of values of type T, each produced by the implementation of the Supplier<T>interface that was passed into the method as a parameter.

The Supplier<T> is a functional interface, which means it has only one abstract method (a method that has to be implemented). In the case of the…