Modifier and Type | Method and Description |
---|---|
static <T> Stream.Builder<T> |
add(Stream.Builder<T> builder,
T t)
Adds an element to the
Stream being built represented by the
Stream.Builder argument. |
static <T> Stream.Builder<T> |
builder()
Returns a builder for a
Stream . |
static <T> Stream<T> |
concat(Stream<? extends T> a,
Stream<? extends T> b)
Creates a lazily concatenated
Stream whose elements are all the
elements of the first stream followed by all the elements of the
second stream. |
static <T> Stream<T> |
empty()
Returns an empty sequential
Stream . |
static <T> Stream<T> |
generate(Supplier<T> s)
Returns an infinite sequential unordered
Stream where each
element is generated by the provided Supplier . |
static <T> Stream<T> |
iterate(T seed,
UnaryOperator<T> f)
Returns an infinite sequential ordered
Stream produced by iterative
application of a function f to an initial element seed ,
producing a Stream consisting of seed , f(seed) ,
f(f(seed)) , etc. |
static <T> Stream<T> |
of(T... values)
Returns a sequential ordered
Stream whose elements are the
specified values. |
static <T> Stream<T> |
of(T t)
Returns a sequential
Stream containing a single element. |
static <T> Stream<T> |
ofNullable(T t)
Returns a sequential
Stream containing a single element, if
non-null, otherwise returns an empty Stream . |
public static <T> Stream.Builder<T> builder()
Stream
.T
- type of elementspublic static <T> Stream<T> empty()
Stream
.T
- the type of stream elementspublic static <T> Stream<T> of(T t)
Stream
containing a single element.T
- the type of stream elementst
- the single elementpublic static <T> Stream<T> ofNullable(T t)
Stream
containing a single element, if
non-null, otherwise returns an empty Stream
.T
- the type of stream elementst
- the single elementpublic static <T> Stream<T> of(T... values)
Stream
whose elements are the
specified values.T
- the type of stream elementsvalues
- the elements of the new streampublic static <T> Stream<T> iterate(T seed, UnaryOperator<T> f)
Stream
produced by iterative
application of a function f
to an initial element seed
,
producing a Stream
consisting of seed
, f(seed)
,
f(f(seed))
, etc.
The first element (position 0
) in the Stream
will be
the provided seed
. For n > 0
, the element at position
n
, will be the result of applying the function f
to the
element at position n - 1
.
T
- the type of stream elementsseed
- the initial elementf
- a function to be applied to the previous element to produce
a new elementStream
public static <T> Stream<T> generate(Supplier<T> s)
Stream
where each
element is generated by the provided Supplier
. This is
suitable for generating constant streams, streams of random elements,
etc.T
- the type of stream elementss
- the Supplier
of generated elementsStream
public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
Stream
whose elements are all the
elements of the first stream followed by all the elements of the
second stream. The resulting stream is ordered if both
of the input streams are ordered, and parallel if either of the input
streams is parallel. When the resulting stream is closed, the close
handlers for both input streams are invoked.
Implementation Note:
Use caution when constructing streams from repeated concatenation.
Accessing an element of a deeply concatenated stream can result in deep
call chains, or even StackOverflowError
.
T
- The type of stream elementsa
- the first streamb
- the second streampublic static <T> Stream.Builder<T> add(Stream.Builder<T> builder, T t)
Stream
being built represented by the
Stream.Builder
argument.
Implementation Requirements:
The default implementation behaves as if:
builder.accept(t)
return builder;
T
- the type of stream elementsbuilder
- the Stream.Builder
to uset
- the element to addIllegalStateException
- if the builder has already transitioned to
the built stateCopyright © 2015. All rights reserved.