Here we can learn how to iterate a stream with Stream.iterate.
Source Code
package com.beginner.examples;
import java.util.stream.Stream;
public class StreamIterateExample {
public static void main(String[] args){
//use Stream.iterate().
Stream.iterate(1, i -> i + 2).limit(2).forEach(x -> System.out.println(x));
}
}
Output:
1
3
References
Imported packages in Java documentation: