Two static methods of the Stream interface allow us to generate a stream of values using an iterative process similar to the traditional for loop:
- Stream<T> iterate(T seed, UnaryOperator<T> func): Creates an infinite sequential Stream object, based on the iterative application of the second parameter (a func function) to the first seed parameter, producing a stream of seed, f(seed), and f(f(seed)) values.
- Stream<T> iterate(T seed, Predicate<T> hasNext, UnaryOperator<T> next): Creates a finite sequential Stream object based on the iterative application of the third parameter (the next function) to the first seed parameter, producing a stream of seed, f(seed), and f(f(seed)), values, as long as the third parameter ...