Java Stream Create asStream(Iterable sourceIterable)

Here you can find the source of asStream(Iterable sourceIterable)

Description

as Stream

License

Apache License

Declaration

public static <T> Stream<T> asStream(Iterable<T> sourceIterable) 

Method Source Code


//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 {
    public static <T> Stream<T> asStream(Iterable<T> sourceIterable) {
        return asStream(sourceIterable.iterator());
    }//w  w  w.j ava  2 s .  c  o  m

    public static <T> Stream<T> asStream(Iterator<T> sourceIterator) {
        return asStream(sourceIterator, false);
    }

    public static <T> Stream<T> asStream(Iterator<T> sourceIterator, boolean parallel) {
        Iterable<T> iterable = () -> sourceIterator;
        return StreamSupport.stream(iterable.spliterator(), parallel);
    }
}

Related

  1. asStream(Collection source, boolean parallel)
  2. asStream(Iterator iter)
  3. asStream(Iterator sourceIterator)
  4. asStream(T... objs)
  5. asStream(T[] items)