Fundamentals

Default Methods

Collections

Idioms and Techniques

Design Rationale

Advanced Questions

How can I turn an Iterator or an Iterable into a Stream?

Iterator

Turning an Iterator into a Stream is a bit involved. First, you turn the Iterator into a Spliterator. Second, you turn that Spliterator into a Stream. For example, this turns an Iterator iterator into an ordered, sequential stream:

StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false);

The reason for this two-step process is that there are options you need […]