0

Java 8 – Convert Iterator to Stream

Although not a common scenario, some libraries just return Iterator instead of actual Stream or Collection objects.

Iterator only

Consider these codes. Imagine they belong to some third-party library.

As you can see, to get the contents of someData you need to go through an Iterator.

StreamSupport

Java 8 has StreamSupport to allow us to create a Stream object.

The output for these codes: