Here you can find the source of toStream(final T source)
public static final <T> Stream<T> toStream(final T source)
//package com.java2s; /*//from w ww .j a v a 2 s . com * Copyright (c) 2018, The Modern Way. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.stream.DoubleStream; import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; public class Main { public static final <T> Stream<T> toStream(final T source) { return Stream.of(source); } @SafeVarargs public static final <T> Stream<T> toStream(final T... source) { if ((null == source) || (source.length == 0)) { return Stream.empty(); } if (source.length == 1) { return Stream.of(source[0]); } return Stream.of(source); } public static final IntStream toStream(final int source) { return IntStream.of(source); } public static final IntStream toStream(final int... source) { if ((null == source) || (source.length == 0)) { return IntStream.empty(); } if (source.length == 1) { return IntStream.of(source[0]); } return IntStream.of(source); } public static final LongStream toStream(final long source) { return LongStream.of(source); } public static final LongStream toStream(final long... source) { if ((null == source) || (source.length == 0)) { return LongStream.empty(); } if (source.length == 1) { return LongStream.of(source[0]); } return LongStream.of(source); } public static final DoubleStream toStream(final double source) { return DoubleStream.of(source); } public static final DoubleStream toStream(final double... source) { if ((null == source) || (source.length == 0)) { return DoubleStream.empty(); } if (source.length == 1) { return DoubleStream.of(source[0]); } return DoubleStream.of(source); } }