Java Stream of stream(Iterator iterator)

Here you can find the source of stream(Iterator iterator)

Description

stream

License

Apache License

Declaration

public static <T> Stream<T> stream(Iterator<T> iterator) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class Main {
    public final static int DEFAULT_ITERATOR_SPLITERATOR_FLAGS = (Spliterator.CONCURRENT | Spliterator.ORDERED);

    public static <T> Stream<T> stream(Iterator<T> iterator) {
        return stream(iterator, -1);
    }//from  ww w.j  ava  2  s . c o m

    public static <T> Stream<T> stream(Iterator<T> iterator, long size) {
        return StreamSupport.stream(
                ((size >= 0)
                        ? Spliterators.spliterator(iterator, size,
                                (DEFAULT_ITERATOR_SPLITERATOR_FLAGS | Spliterator.SIZED))
                        : Spliterators.spliteratorUnknownSize(iterator, DEFAULT_ITERATOR_SPLITERATOR_FLAGS)),
                false);
    }
}

Related

  1. stream(Iterable iterable)
  2. stream(Iterable input)
  3. stream(Iterable iterable)
  4. stream(Iterable iterable)
  5. stream(Iterable it)
  6. stream(Object values)
  7. streamEquals(Stream a, Stream b)
  8. streamInt(int max)
  9. streamOf (final Iterable iterable)