public final class LongStreams extends Object
takeWhile()
,
dropWhile()
) in the LongStream
interface.Modifier and Type | Method and Description |
---|---|
static LongStream.Builder |
builder()
Returns a builder for a
LongStream . |
static LongStream |
concat(LongStream a,
LongStream 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 LongStream |
dropWhile(LongStream stream,
LongPredicate predicate)
Returns a stream consisting of the remaining elements of the passed
stream after discarding elements that match the given predicate up to,
but not discarding, the first element encountered that does not match
the predicate.
|
static LongStream |
empty()
Returns an empty sequential
LongStream . |
static LongStream |
generate(LongSupplier s)
Returns an infinite sequential unordered stream where each element is
generated by the provided
LongSupplier . |
static LongStream |
iterate(long seed,
LongUnaryOperator f)
Returns an infinite sequential ordered
LongStream 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 LongStream |
of(long... values)
Returns a sequential ordered stream whose elements are the specified values.
|
static LongStream |
of(long t)
Returns a sequential
LongStream containing a single element. |
static LongStream |
range(long startInclusive,
long endExclusive)
Returns a sequential ordered
LongStream from startInclusive
(inclusive) to endExclusive (exclusive) by an incremental step of
1 . |
static LongStream |
rangeClosed(long startInclusive,
long endInclusive)
Returns a sequential ordered
LongStream from startInclusive
(inclusive) to endInclusive (inclusive) by an incremental step of
1 . |
static LongStream |
takeWhile(LongStream stream,
LongPredicate predicate)
Returns a stream consisting of elements of the passed stream that match
the given predicate up to, but discarding, the first element encountered
that does not match the predicate.
|
public static LongStream takeWhile(LongStream stream, LongPredicate predicate)
stream
- the stream to wrap for the takeWhile()
operationpredicate
- a non-interfering,
predicate to apply to each element to determine if it
should be included, or it and all subsequently
encountered elements be discarded.public static LongStream dropWhile(LongStream stream, LongPredicate predicate)
This is a stateful intermediate operation.
stream
- the stream to wrap for the dropWhile()
operationpredicate
- a non-interfering,
predicate to apply to each element to determine if it
should be discarded, or it and all subsequently
encountered elements be included.public static LongStream.Builder builder()
LongStream
.public static LongStream empty()
LongStream
.public static LongStream of(long t)
LongStream
containing a single element.t
- the single elementpublic static LongStream of(long... values)
values
- the elements of the new streampublic static LongStream iterate(long seed, LongUnaryOperator f)
LongStream
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 LongStream
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
.
seed
- the initial elementf
- a function to be applied to the previous element to produce
a new elementLongStream
public static LongStream generate(LongSupplier s)
LongSupplier
. This is suitable for
generating constant streams, streams of random elements, etc.s
- the LongSupplier
for generated elementsLongStream
public static LongStream range(long startInclusive, long endExclusive)
LongStream
from startInclusive
(inclusive) to endExclusive
(exclusive) by an incremental step of
1
.
API Note:
An equivalent sequence of increasing values can be produced
sequentially using a for
loop as follows:
for (long i = startInclusive; i < endExclusive ; i++) { ... }
startInclusive
- the (inclusive) initial valueendExclusive
- the exclusive upper boundLongStream
for the range of long
elementspublic static LongStream rangeClosed(long startInclusive, long endInclusive)
LongStream
from startInclusive
(inclusive) to endInclusive
(inclusive) by an incremental step of
1
.
API Note:
An equivalent sequence of increasing values can be produced
sequentially using a for
loop as follows:
for (long i = startInclusive; i <= endInclusive ; i++) { ... }
startInclusive
- the (inclusive) initial valueendInclusive
- the inclusive upper boundLongStream
for the range of long
elementspublic static LongStream concat(LongStream a, LongStream b)
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
.
Subsequent changes to the sequential/parallel execution mode of the returned stream are not guaranteed to be propagated to the input streams.
a
- the first streamb
- the second streamCopyright © 2016. All rights reserved.