If you have a class implementing Iterable, you can get a Stream over elements just by:
Iterable<String> iterable = () -> legacyClass.iterator();
StreamSupport.stream(iterable.spliterator(), false);If the class doesn't already have a stream method. But if you only have an iterator and still want to use streams, you can use the fact that Iterable is a functional interface since it has only one non-default method, so if you already have an iterator, you can create Iterable by:
Iterable<String> iterable = () -> iterator;It returns always the same iterator, so it is more a hack then a solution, but approach can be used by one of those classes that can produce iterator but are not implementing Iterable interface.
Iterable<String> iterable = () -> legacyClass.iterator();
return StreamSupport.stream(iterable.spliterator(), false);