Why is Stream<T> not an Iterable<T> ?

Brian Goetz brian.goetz at oracle.com
Wed Mar 27 08:03:30 PDT 2013

> I still wonder what is supposed to happen if stream.iterator() is
> called repeatedly on Stream object?
> The Javadoc only says "Return an iterator for the elements of this
> stream. This is a terminal operation."

Its a terminal operation.  If you try to call another terminal operation, it will fail because the stream is used.  

> If it is a terminal operation, I guess it internally creates a
> collection.

Not at all.  It creates an Iterator.  Streams are lazy.  Iterators are lazy.  No problem.

More information about the lambda-dev mailing list