src/share/classes/java/util/stream/Stream.java

Print this page




 810 
 811     /**
 812      * Returns a sequential {@code Stream} containing a single element.
 813      *
 814      * @param t the single element
 815      * @param <T> the type of stream elements
 816      * @return a singleton sequential stream
 817      */
 818     public static<T> Stream<T> of(T t) {
 819         return StreamSupport.stream(new Streams.StreamBuilderImpl<>(t), false);
 820     }
 821 
 822     /**
 823      * Returns a sequential stream whose elements are the specified values.
 824      *
 825      * @param <T> the type of stream elements
 826      * @param values the elements of the new stream
 827      * @return the new stream
 828      */
 829     @SafeVarargs

 830     public static<T> Stream<T> of(T... values) {
 831         return Arrays.stream(values);
 832     }
 833 
 834     /**
 835      * Returns an infinite sequential {@code Stream} produced by iterative
 836      * application of a function {@code f} to an initial element {@code seed},
 837      * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 838      * {@code f(f(seed))}, etc.
 839      *
 840      * <p>The first element (position {@code 0}) in the {@code Stream} will be
 841      * the provided {@code seed}.  For {@code n > 0}, the element at position
 842      * {@code n}, will be the result of applying the function {@code f} to the
 843      * element at position {@code n - 1}.
 844      *
 845      * @param <T> the type of stream elements
 846      * @param seed the initial element
 847      * @param f a function to be applied to to the previous element to produce
 848      *          a new element
 849      * @return a new sequential {@code Stream}




 810 
 811     /**
 812      * Returns a sequential {@code Stream} containing a single element.
 813      *
 814      * @param t the single element
 815      * @param <T> the type of stream elements
 816      * @return a singleton sequential stream
 817      */
 818     public static<T> Stream<T> of(T t) {
 819         return StreamSupport.stream(new Streams.StreamBuilderImpl<>(t), false);
 820     }
 821 
 822     /**
 823      * Returns a sequential stream whose elements are the specified values.
 824      *
 825      * @param <T> the type of stream elements
 826      * @param values the elements of the new stream
 827      * @return the new stream
 828      */
 829     @SafeVarargs
 830     @SuppressWarnings("varargs") // Creating a stream for an array is safe
 831     public static<T> Stream<T> of(T... values) {
 832         return Arrays.stream(values);
 833     }
 834 
 835     /**
 836      * Returns an infinite sequential {@code Stream} produced by iterative
 837      * application of a function {@code f} to an initial element {@code seed},
 838      * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 839      * {@code f(f(seed))}, etc.
 840      *
 841      * <p>The first element (position {@code 0}) in the {@code Stream} will be
 842      * the provided {@code seed}.  For {@code n > 0}, the element at position
 843      * {@code n}, will be the result of applying the function {@code f} to the
 844      * element at position {@code n - 1}.
 845      *
 846      * @param <T> the type of stream elements
 847      * @param seed the initial element
 848      * @param f a function to be applied to to the previous element to produce
 849      *          a new element
 850      * @return a new sequential {@code Stream}