Java Stream Create asStream(Collection source, boolean parallel)

Here you can find the source of asStream(Collection source, boolean parallel)

Description

Returns the given collection as stream.

License

LGPL

Parameter

Parameter Description
T the generic type
source the source
parallel <code>true</code> if the stream should be a parallel stream

Return

the stream

Declaration

public static <T> Stream<T> asStream(Collection<T> source, boolean parallel) 

Method Source Code

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

import java.util.Collection;

import java.util.stream.Stream;

public class Main {
    /**/*  w w  w  .ja va  2s  . co m*/
     * Returns the given collection as stream.
     *
     * @param <T>
     *            the generic type
     * @param source
     *            the source
     * @param parallel
     *            <code>true</code> if the stream should be a parallel stream
     * @return the stream
     */
    public static <T> Stream<T> asStream(Collection<T> source, boolean parallel) {
        return parallel ? source.parallelStream() : source.stream();
    }
}

Related

  1. asStream(Iterable sourceIterable)
  2. asStream(Iterator iter)
  3. asStream(Iterator sourceIterator)
  4. asStream(T... objs)