Here you can find the source of prepend(final T first, final Stream
Parameter | Description |
---|---|
first | a parameter |
rest | a parameter |
public static <T> Stream<T> prepend(final T first, final Stream<T> rest)
//package com.java2s; //License from project: Open Source License import java.util.stream.Stream; public class Main { public static final String ERR_FIRST_STREAM_ELEM_CANNOT_BE_NULL = "First stream element cannot be null."; /**// ww w. ja v a 2s . co m * Prepends a non-null {@code first} to stream {@code rest}, returning a new stream. * * @param first * @param rest * @return */ public static <T> Stream<T> prepend(final T first, final Stream<T> rest) { if (first == null) { throw new NullPointerException(ERR_FIRST_STREAM_ELEM_CANNOT_BE_NULL); } final Stream<T> xs = Stream.of(first); return Stream.concat(xs, rest); } /** * Creates a new stream from the provided values. * * @param first * @param rest * @return */ public static <T> Stream<T> of(final T first, final T... rest) { if (first == null) { throw new NullPointerException(ERR_FIRST_STREAM_ELEM_CANNOT_BE_NULL); } final Stream<T> xs = Stream.of(first); final Stream<T> ys = Stream.of(rest); return Stream.concat(xs, ys); } }