Re:SICP Goodness – Why you don't need looping constructs
by wffurr on Friday June 29, 2018 @07:36AM
(#17423866)
It depends on whether the underlying stream supports "peek". If not, in order to determine whether there is a next element, the iterator must consume the next element and hold it in local memory until a call to next.
That can matter in certain cases of large objects or slow or side-effecting stream access
"boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next() would return an element rather than throwing an exception.)
Returns: true if the iteration has more elements"
https://docs.oracle.com/javase/8/docs/api/java/util/Iterator...
Also, the for-each construct takes an Iterable, not an Iterator, though Iterable produces Iterators.