How to iterate with foreach loop over java 8 stream
By definition foreach loop requires an Iterable to be passed in. It can be achieved with anonymous class: for (String s : new Iterable<String>() { @Override public Iterator<String> iterator() { return stream.iterator(); } }) { writer.append(s); } This can be simplified with lambda because Iterable is a functional interface: for (String s : (Iterable<String>) () … Read more