Java Stream Create asStream(T[] items)

Here you can find the source of asStream(T[] items)

Description

as Stream

License

Open Source License

Declaration

public static <T> Stream<T> asStream(T[] items) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

public class Main {
    public static <T> Stream<T> asStream(T[] items) {
        return nullGuard(items).stream();
    }//w  ww  .j  a v a  2s .  co m

    private static <T> List<T> nullGuard(T[] items) {
        if (items == null) {
            return Collections.emptyList();
        } else {
            return Arrays.asList(items);
        }
    }
}

Related

  1. asStream(Collection source, boolean parallel)
  2. asStream(Iterable sourceIterable)
  3. asStream(Iterator iter)
  4. asStream(Iterator sourceIterator)
  5. asStream(T... objs)