Question: In Java 8 we have the class [Stream<T>](http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html), which curiously have a method

```
Iterator<T> iterator()

```

So you would expect it to implement interface [Iterable<T>](http://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html), which requires exactly this method, but that's not the case.

When I want to iterate over a Stream using a foreach loop, I have to do something like

```
public static Iterable<T> getIterable(Stream<T> s) {
    return new Iterable<T> {
        @Override
        public Iterator<T> iterator() {
            return s.iterator();
        }
    };
}

for (T element : getIterable(s)) { ... }

```

Am I missing something here?

Answer: 
People have already asked the same [on the mailing list](http://mail.openjdk.java.net/pipermail/lambda-dev/2013-March/008876.html) ☺. The main reason is Iterable also has a re-iterable semantic, while Stream is not.

> 
> I think the main reason is that `Iterable` implies reusability, whereas `Stream` is something that can only be used once — more like an `Iterator`.
> 
> 
> If `Stream` extended `Iterable` then existing code might be surprised when it receives an `Iterable` that throws an `Exception` the
>  second time they do `for (element : iterable)`.
> 
> 
>
`Stream` does not implement `Iterable`. The general understanding of `Iterable` is anything that can be iterated upon, often again and again. `Stream` may not be replayable.

The only workaround that I can think of, where an iterable based on a stream is replayable too, is to re-create the stream. I am using a `Supplier` below to create a new instance of stream, everytime a new iterator is created. 

```
    Supplier<Stream<Integer>> streamSupplier = () -> Stream.of(10);
    Iterable<Integer> iterable = () -> streamSupplier.get().iterator();
    for(int i : iterable) {
        System.out.println(i);
    }
    // Can iterate again
    for(int i : iterable) {
        System.out.println(i);
    }

```