// Java program to get a Stream// from a given Iteratorimportjava.util.*;importjava.util.stream.*;classGFG{// Function to get the StreampublicstaticStreamgetStreamFromIterator(Iterator iterator){// Convert the iterator to SpliteratorSpliterator
spliterator =Spliterators.spliteratorUnknownSize(iterator,0);// Get a Sequential Stream from spliteratorreturnStreamSupport.stream(spliterator,false);}// Driver codepublicstaticvoidmain(String[] args){// Get the IteratorIterator
iterator =Arrays.asList(1,2,3,4,5).iterator();// Get the Stream from the IteratorStream
stream =getStreamFromIterator(iterator);// Print the elements of stream
stream.forEach(s ->System.out.println(s));}}