SyntaxFix
Write A Post
Hire A Developer
Questions
Another way to do this on Java 9+ using Stream::iterate(T, Predicate, UnaryOperator):
Stream::iterate(T, Predicate, UnaryOperator)
Stream.iterate(iterator, Iterator::hasNext, UnaryOperator.identity()) .map(Iterator::next) .forEach(System.out::println);