Is it possible to create a Stream from an Iterator, in which the sequence of objects is the same as that generated by calling the iterator\'s next() method repeatedly? The s
As it was written by Karol Król for infinite stream you can use this:
Stream.generate(iterator::next)
but you can also use it for finite stream with takeWhile since Java 9
Stream.generate(iterator::next).takeWhile((v) -> iterator.hasNext())