Convert Iterator to Iterable
import java.util.Iterator;
public class Utils {
public static <E> Iterable<E> iterable(final Iterator<E> iterator) {
if (iterator == null) {
throw new NullPointerException();
}
return new Iterable<E>() {
public Iterator<E> iterator() {
return iterator;
}
};
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection Iterator:
- Convert Iterator to Iterable
- Remove item with Iterator