Here you can find the source of iteratorToFiniteStream(Iterator
static <T> Stream<T> iteratorToFiniteStream(Iterator<T> iterator, boolean parallel)
//package com.java2s; //License from project: Apache License import java.util.Iterator; import java.util.stream.Stream; import java.util.stream.StreamSupport; public class Main { static <T> Stream<T> iteratorToFiniteStream(Iterator<T> iterator, boolean parallel) { final Iterable<T> iterable = () -> iterator; return StreamSupport.stream(iterable.spliterator(), parallel); }// w w w. j a v a2 s. co m }