Is there a Java 8 stream operation that limits a (potentially infinite) Stream until the first element fails to match a predicate?
Stream
In Java 9 we can use
If you have different problem, different solution may be needed but for your current problem, I would simply go with:
IntStream .iterate(1, n -> n + 1) .limit(10) .forEach(System.out::println);