public final class IntStream
extends java.lang.Object
implements java.io.Closeable
int
primitive specialization of Stream.| Modifier and Type | Class and Description |
|---|---|
static interface |
IntStream.IntMapMultiConsumer
Represents an operation on two input arguments.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(IntPredicate predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
anyMatch(IntPredicate predicate)
Returns whether any elements of this stream match the provided
predicate.
|
IntStream |
append(IntStream stream)
Appends given
IntStream to current and returns a new stream. |
Stream<java.lang.Integer> |
boxed()
Returns a
Stream consisting of the elements of this stream,
each boxed to an Integer. |
void |
close()
Causes close handler to be invoked if it exists.
|
<R> R |
collect(Supplier<R> supplier,
ObjIntConsumer<R> accumulator)
Collects elements to
supplier provided container by applying the given accumulation function. |
static IntStream |
concat(IntStream a,
IntStream 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 IntStream |
concat(IntStream a,
IntStream b,
IntStream... rest)
Lazily concatenates three or more streams.
|
long |
count()
Returns the count of elements in this stream.
|
<R> R |
custom(Function<IntStream,R> function)
Applies custom operator on stream.
|
IntStream |
distinct()
Returns a stream consisting of the distinct elements of this stream.
|
IntStream |
dropWhile(IntPredicate predicate)
Drops elements while the predicate is true and returns the rest.
|
static IntStream |
empty()
Returns an empty stream.
|
IntStream |
filter(IntPredicate predicate)
Returns a stream consisting of the elements of this stream that match
the given predicate.
|
IntStream |
filterIndexed(IndexedIntPredicate predicate)
Returns an
IntStream with elements that satisfy the given IndexedIntPredicate. |
IntStream |
filterIndexed(int from,
int step,
IndexedIntPredicate predicate)
Returns an
IntStream with elements that satisfy the given IndexedIntPredicate. |
IntStream |
filterNot(IntPredicate predicate)
Returns a stream consisting of the elements of this stream that don't
match the given predicate.
|
OptionalInt |
findFirst()
Returns an
OptionalInt describing the first element of this
stream, or an empty OptionalInt if the stream is empty. |
int |
findFirstOrElse(int other)
Returns the first element if stream is not empty,
otherwise returns
other. |
OptionalInt |
findLast()
Returns the last element wrapped by
OptionalInt class. |
OptionalInt |
findSingle()
Returns the single element wrapped by
OptionalInt class. |
IntStream |
flatMap(IntFunction<? extends IntStream> mapper)
Returns a stream consisting of the results of replacing each element of
this stream with the contents of a mapped stream produced by applying
the provided mapping function to each element.
|
void |
forEach(IntConsumer action)
Performs an action for each element of this stream.
|
void |
forEachIndexed(IndexedIntConsumer action)
Performs the given indexed action on each element.
|
void |
forEachIndexed(int from,
int step,
IndexedIntConsumer action)
Performs the given indexed action on each element.
|
static IntStream |
generate(IntSupplier s)
Returns an infinite sequential unordered stream where each element is
generated by the provided
IntSupplier. |
static IntStream |
iterate(int seed,
IntPredicate predicate,
IntUnaryOperator op)
Creates an
IntStream by iterative application IntUnaryOperator function
to an initial element seed, conditioned on satisfying the supplied predicate. |
static IntStream |
iterate(int seed,
IntUnaryOperator f)
Returns an infinite sequential ordered
IntStream 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. |
PrimitiveIterator.OfInt |
iterator()
Returns internal
IntStream iterator. |
IntStream |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
IntStream |
map(IntUnaryOperator mapper)
Returns an
IntStream consisting of the results of applying the given
function to the elements of this stream. |
IntStream |
mapIndexed(IntBinaryOperator mapper)
Returns an
IntStream with elements that obtained by applying the given IntBinaryOperator. |
IntStream |
mapIndexed(int from,
int step,
IntBinaryOperator mapper)
Returns an
IntStream with elements that obtained by applying the given IntBinaryOperator. |
IntStream |
mapMulti(IntStream.IntMapMultiConsumer mapper)
Returns a stream consisting of the results of replacing each element of
this stream with the contents of a mapped stream produced by applying
the provided mapping function to each element.
|
DoubleStream |
mapToDouble(IntToDoubleFunction mapper)
Returns a
DoubleStream consisting of the results of applying the given
function to the elements of this stream. |
LongStream |
mapToLong(IntToLongFunction mapper)
Returns a
LongStream consisting of the results of applying the given
function to the elements of this stream. |
<R> Stream<R> |
mapToObj(IntFunction<? extends R> mapper)
Returns a
Stream consisting of the results of applying the given
function to the elements of this stream. |
OptionalInt |
max()
Returns an
OptionalInt describing the maximum element of this
stream, or an empty optional if this stream is empty. |
OptionalInt |
min()
Returns an
OptionalInt describing the minimum element of this
stream, or an empty optional if this stream is empty. |
boolean |
noneMatch(IntPredicate predicate)
Returns whether no elements of this stream match the provided predicate.
|
static IntStream |
of(int... values)
Returns stream whose elements are the specified values.
|
static IntStream |
of(int t)
Returns stream which contains single element passed as parameter.
|
static IntStream |
of(PrimitiveIterator.OfInt iterator)
Creates a
IntStream from PrimitiveIterator.OfInt. |
static IntStream |
ofCodePoints(java.lang.CharSequence charSequence)
Creates an
IntStream of code point values from the given sequence. |
IntStream |
onClose(java.lang.Runnable closeHandler)
Adds close handler to the current stream.
|
IntStream |
peek(IntConsumer action)
Returns a stream consisting of the elements of this stream, additionally
performing the provided action on each element as elements are consumed
from the resulting stream.
|
IntStream |
prepend(IntStream stream)
Prepends given
IntStream to current and returns a new stream. |
static IntStream |
range(int startInclusive,
int endExclusive)
Returns a sequential ordered
IntStream from startInclusive
(inclusive) to endExclusive (exclusive) by an incremental step of
1. |
static IntStream |
rangeClosed(int startInclusive,
int endInclusive)
Returns a sequential ordered
IntStream from startInclusive
(inclusive) to endInclusive (inclusive) by an incremental step of
1. |
OptionalInt |
reduce(IntBinaryOperator op)
Performs a reduction on the elements of this stream, using an
associative accumulation function, and returns an
OptionalInt
describing the reduced value, if any. |
int |
reduce(int identity,
IntBinaryOperator op)
Performs a reduction on the elements of this stream, using the provided
identity value and an associative accumulation function, and returns the
reduced value.
|
IntStream |
sample(int stepWidth)
Samples the
IntStream by emitting every n-th element. |
IntStream |
scan(IntBinaryOperator accumulator)
Returns a
IntStream produced by iterative application of a accumulation function
to reduction value and next element of the current stream. |
IntStream |
scan(int identity,
IntBinaryOperator accumulator)
Returns a
IntStream produced by iterative application of a accumulation function
to an initial element identity and next element of the current stream. |
int |
single()
Returns the single element of stream.
|
IntStream |
skip(long n)
Returns a stream consisting of the remaining elements of this stream
after discarding the first
n elements of the stream. |
IntStream |
sorted()
Returns a stream consisting of the elements of this stream in sorted
order.
|
IntStream |
sorted(java.util.Comparator<java.lang.Integer> comparator)
Returns
IntStream with sorted elements (as determinated by provided Comparator). |
int |
sum()
Returns the sum of elements in this stream.
|
IntStream |
takeUntil(IntPredicate stopPredicate)
Takes elements while the predicate returns
false. |
IntStream |
takeWhile(IntPredicate predicate)
Takes elements while the predicate returns
true. |
int[] |
toArray()
Returns an array containing the elements of this stream.
|
@NotNull public static IntStream empty()
@NotNull public static IntStream of(@NotNull PrimitiveIterator.OfInt iterator)
IntStream from PrimitiveIterator.OfInt.iterator - the iterator with elements to be passed to streamIntStreamjava.lang.NullPointerException - if iterator is null@NotNull public static IntStream of(@NotNull int... values)
values - the elements of the new streamjava.lang.NullPointerException - if values is null@NotNull public static IntStream of(int t)
t - element of the stream@NotNull public static IntStream ofCodePoints(@NotNull java.lang.CharSequence charSequence)
IntStream of code point values from the given sequence.
Any surrogate pairs encountered in the sequence are combined as if by Character.toCodePoint and the result is passed to the stream.
Any other code units, including ordinary BMP characters, unpaired surrogates, and
undefined code units, are zero-extended to int values which are then
passed to the stream.charSequence - the sequence where to get all code points values.@NotNull public static IntStream range(int startInclusive, int endExclusive)
IntStream from startInclusive
(inclusive) to endExclusive (exclusive) by an incremental step of
1.startInclusive - the (inclusive) initial valueendExclusive - the exclusive upper boundIntStream for the range of int
elements@NotNull public static IntStream rangeClosed(int startInclusive, int endInclusive)
IntStream from startInclusive
(inclusive) to endInclusive (inclusive) by an incremental step of
1.startInclusive - the (inclusive) initial valueendInclusive - the inclusive upper boundIntStream for the range of int
elements@NotNull public static IntStream generate(@NotNull IntSupplier s)
IntSupplier. This is suitable for
generating constant streams, streams of random elements, etc.s - the IntSupplier for generated elementsIntStreamjava.lang.NullPointerException - if s is null@NotNull public static IntStream iterate(int seed, @NotNull IntUnaryOperator f)
IntStream 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 IntStream 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.
Example:
seed: 1 f: (a) -> a + 5 result: [1, 6, 11, 16, ...]
seed - the initial elementf - a function to be applied to the previous element to produce
a new elementIntStreamjava.lang.NullPointerException - if f is null@NotNull public static IntStream iterate(int seed, @NotNull IntPredicate predicate, @NotNull IntUnaryOperator op)
IntStream by iterative application IntUnaryOperator function
to an initial element seed, conditioned on satisfying the supplied predicate.
Example:
seed: 0 predicate: (a) -> a < 20 f: (a) -> a + 5 result: [0, 5, 10, 15]
seed - the initial valuepredicate - a predicate to determine when the stream must terminateop - operator to produce new element by previous onejava.lang.NullPointerException - if op is null@NotNull public static IntStream concat(@NotNull IntStream a, @NotNull IntStream b)
Example:
stream a: [1, 2, 3, 4] stream b: [5, 6] result: [1, 2, 3, 4, 5, 6]
a - the first streamb - the second streamjava.lang.NullPointerException - if a or b is null@NotNull public static IntStream concat(@NotNull IntStream a, @NotNull IntStream b, @NotNull IntStream... rest)
Example:
stream a: [1, 2, 3, 4] stream b: [5, 6] stream c: [7] stream d: [8, 9, 10] result: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a - the first streamb - the second streamrest - the rest of streamsjava.lang.NullPointerException - if a or b
or rest is nullpublic PrimitiveIterator.OfInt iterator()
IntStream iterator.IntStream iterator.@Nullable
public <R> R custom(@NotNull
Function<IntStream,R> function)
IntStream for intermediate operations,
or any value for terminal operation.
Operator examples:
// Intermediate operator
public class Zip<T> implements Function<IntStream, IntStream> {
@Override
public IntStream apply(IntStream firstStream) {
final PrimitiveIterator.OfInt it1 = firstStream.iterator();
final PrimitiveIterator.OfInt it2 = secondStream.iterator();
return IntStream.of(new PrimitiveIterator.OfInt() {
@Override
public boolean hasNext() {
return it1.hasNext() && it2.hasNext();
}
@Override
public int nextInt() {
return combiner.applyAsInt(it1.nextInt(), it2.nextInt());
}
});
}
}
// Intermediate operator based on existing stream operators
public class SkipAndLimit implements UnaryOperator<IntStream> {
private final int skip, limit;
public SkipAndLimit(int skip, int limit) {
this.skip = skip;
this.limit = limit;
}
@Override
public IntStream apply(IntStream stream) {
return stream.skip(skip).limit(limit);
}
}
// Terminal operator
public class Average implements Function<IntStream, Double> {
long count = 0, sum = 0;
@Override
public Double apply(IntStream stream) {
final PrimitiveIterator.OfInt it = stream.iterator();
while (it.hasNext()) {
count++;
sum += it.nextInt();
}
return (count == 0) ? 0 : sum / (double) count;
}
}
R - the type of the resultfunction - a transforming functionjava.lang.NullPointerException - if function is nullStream.custom(com.annimon.stream.function.Function)@NotNull public Stream<java.lang.Integer> boxed()
Stream consisting of the elements of this stream,
each boxed to an Integer.
This is an lazy intermediate operation.
Stream consistent of the elements of this stream,
each boxed to an Integer@NotNull public IntStream prepend(@NotNull IntStream stream)
IntStream to current and returns a new stream.
This is similar to IntStream.concat(stream, this)
Example:
current: [1, 2, 3] stream: [4, 5, 6] result: [4, 5, 6, 1, 2, 3]
stream - the stream to prependconcat(IntStream, IntStream)@NotNull public IntStream append(@NotNull IntStream stream)
IntStream to current and returns a new stream.
This is similar to IntStream.concat(this, stream)
Example:
current: [1, 2, 3] stream: [4, 5, 6] result: [1, 2, 3, 4, 5, 6]
stream - the stream to appendconcat(IntStream, IntStream)@NotNull public IntStream filter(@NotNull IntPredicate predicate)
This is an intermediate operation.
Example:
predicate: (a) -> a > 2 stream: [1, 2, 3, 4, -8, 0, 11] result: [3, 4, 11]
predicate - non-interfering, stateless predicate to apply to each
element to determine if it should be included@NotNull public IntStream filterIndexed(@NotNull IndexedIntPredicate predicate)
IntStream with elements that satisfy the given IndexedIntPredicate.
This is an intermediate operation.
Example:
predicate: (index, value) -> (index + value) > 6 stream: [1, 2, 3, 4, 0, 11] index: [0, 1, 2, 3, 4, 5] sum: [1, 3, 5, 7, 4, 16] filter: [ 7, 16] result: [4, 11]
predicate - the IndexedIntPredicate used to filter elements@NotNull public IntStream filterIndexed(int from, int step, @NotNull IndexedIntPredicate predicate)
IntStream with elements that satisfy the given IndexedIntPredicate.
This is an intermediate operation.
Example:
from: 4 step: 3 predicate: (index, value) -> (index + value) > 15 stream: [1, 2, 3, 4, 0, 11] index: [4, 7, 10, 13, 16, 19] sum: [5, 9, 13, 17, 16, 30] filter: [ 17, 16, 30] result: [4, 0, 11]
from - the initial value of the index (inclusive)step - the step of the indexpredicate - the IndexedIntPredicate used to filter elements@NotNull public IntStream filterNot(@NotNull IntPredicate predicate)
This is an intermediate operation.
predicate - non-interfering, stateless predicate to apply to each
element to determine if it should not be included@NotNull public IntStream map(@NotNull IntUnaryOperator mapper)
IntStream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
Example:
mapper: (a) -> a + 5 stream: [1, 2, 3, 4] result: [6, 7, 8, 9]
mapper - a non-interfering stateless function to apply to
each elementIntStream@NotNull public IntStream mapIndexed(@NotNull IntBinaryOperator mapper)
IntStream with elements that obtained by applying the given IntBinaryOperator.
This is an intermediate operation.
Example:
mapper: (index, value) -> (index * value) stream: [1, 2, 3, 4] index: [0, 1, 2, 3] result: [0, 2, 6, 12]
mapper - the mapper function used to apply to each element@NotNull public IntStream mapIndexed(int from, int step, @NotNull IntBinaryOperator mapper)
IntStream with elements that obtained by applying the given IntBinaryOperator.
This is an intermediate operation.
Example:
from: -2 step: 2 mapper: (index, value) -> (index * value) stream: [ 1, 2, 3, 4] index: [-2, 0, 2, 4] result: [-2, 0, 6, 16]
from - the initial value of the index (inclusive)step - the step of the indexmapper - the mapper function used to apply to each element@NotNull public <R> Stream<R> mapToObj(@NotNull IntFunction<? extends R> mapper)
Stream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
R - the type resultmapper - the mapper function used to apply to each elementStream@NotNull public LongStream mapToLong(@NotNull IntToLongFunction mapper)
LongStream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
mapper - the mapper function used to apply to each elementLongStreamflatMap(com.annimon.stream.function.IntFunction)@NotNull public DoubleStream mapToDouble(@NotNull IntToDoubleFunction mapper)
DoubleStream consisting of the results of applying the given
function to the elements of this stream.
This is an intermediate operation.
mapper - the mapper function used to apply to each elementDoubleStreamflatMap(com.annimon.stream.function.IntFunction)@NotNull public IntStream flatMap(@NotNull IntFunction<? extends IntStream> mapper)
This is an intermediate operation.
Example:
mapper: (a) -> [a, a + 5] stream: [1, 2, 3, 4] result: [1, 6, 2, 7, 3, 8, 4, 9]
mapper - a non-interfering stateless function to apply to each
element which produces an IntStream of new valuesStream.flatMap(Function)@NotNull public IntStream mapMulti(@NotNull IntStream.IntMapMultiConsumer mapper)
This is an intermediate operation.
mapper - the mapper function used to apply to each element for producing replacing elementsStream.mapMulti(com.annimon.stream.function.BiConsumer),
flatMap(com.annimon.stream.function.IntFunction)@NotNull public IntStream distinct()
This is a stateful intermediate operation.
Example:
stream: [1, 4, 2, 3, 3, 4, 1] result: [1, 4, 2, 3]
@NotNull public IntStream sorted()
This is a stateful intermediate operation.
Example:
stream: [3, 4, 1, 2] result: [1, 2, 3, 4]
@NotNull public IntStream sorted(@Nullable java.util.Comparator<java.lang.Integer> comparator)
IntStream with sorted elements (as determinated by provided Comparator).
This is a stateful intermediate operation.
Example:
comparator: (a, b) -> -a.compareTo(b) stream: [1, 2, 3, 4] result: [4, 3, 2, 1]
comparator - the Comparator to compare elementsIntStream@NotNull public IntStream sample(int stepWidth)
IntStream by emitting every n-th element.
This is an intermediate operation.
Example:
stepWidth: 3 stream: [1, 2, 3, 4, 5, 6, 7, 8] result: [1, 4, 7]
stepWidth - step widthIntStreamjava.lang.IllegalArgumentException - if stepWidth is zero or negativeStream.sample(int)@NotNull public IntStream peek(@NotNull IntConsumer action)
This is an intermediate operation.
action - the action to be performed on each element@NotNull public IntStream scan(@NotNull IntBinaryOperator accumulator)
IntStream produced by iterative application of a accumulation function
to reduction value and next element of the current stream.
Produces a IntStream consisting of value1, acc(value1, value2),
acc(acc(value1, value2), value3), etc.
This is an intermediate operation.
Example:
accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: [1, 3, 6, 10, 15]
accumulator - the accumulation functionjava.lang.NullPointerException - if accumulator is null@NotNull public IntStream scan(int identity, @NotNull IntBinaryOperator accumulator)
IntStream produced by iterative application of a accumulation function
to an initial element identity and next element of the current stream.
Produces a IntStream consisting of identity, acc(identity, value1),
acc(acc(identity, value1), value2), etc.
This is an intermediate operation.
Example:
identity: 0 accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: [0, 1, 3, 6, 10, 15]
identity - the initial valueaccumulator - the accumulation functionjava.lang.NullPointerException - if accumulator is null@NotNull public IntStream takeWhile(@NotNull IntPredicate predicate)
true.
This is an intermediate operation.
Example:
predicate: (a) -> a < 3 stream: [1, 2, 3, 4, 1, 2, 3, 4] result: [1, 2]
predicate - the predicate used to take elementsIntStream@NotNull public IntStream takeUntil(@NotNull IntPredicate stopPredicate)
false.
Once predicate condition is satisfied by an element, the stream
finishes with this element.
This is an intermediate operation.
Example:
stopPredicate: (a) -> a > 2 stream: [1, 2, 3, 4, 1, 2, 3, 4] result: [1, 2, 3]
stopPredicate - the predicate used to take elementsIntStream@NotNull public IntStream dropWhile(@NotNull IntPredicate predicate)
This is an intermediate operation.
Example:
predicate: (a) -> a < 3 stream: [1, 2, 3, 4, 1, 2, 3, 4] result: [3, 4, 1, 2, 3, 4]
predicate - the predicate used to drop elementsIntStream@NotNull public IntStream limit(long maxSize)
maxSize in length.
This is a short-circuiting stateful intermediate operation.
Example:
maxSize: 3 stream: [1, 2, 3, 4, 5] result: [1, 2, 3] maxSize: 10 stream: [1, 2] result: [1, 2]
maxSize - the number of elements the stream should be limited tojava.lang.IllegalArgumentException - if maxSize is negative@NotNull public IntStream skip(long n)
n elements of the stream.
If this stream contains fewer than n elements then an
empty stream will be returned.
This is a stateful intermediate operation.
Example:
n: 3 stream: [1, 2, 3, 4, 5] result: [4, 5] n: 10 stream: [1, 2] result: []
n - the number of leading elements to skipjava.lang.IllegalArgumentException - if n is negativepublic void forEach(@NotNull
IntConsumer action)
This is a terminal operation.
action - a non-interfering action to perform on the elementspublic void forEachIndexed(@NotNull
IndexedIntConsumer action)
This is a terminal operation.
action - the action to be performed on each elementpublic void forEachIndexed(int from,
int step,
@NotNull
IndexedIntConsumer action)
This is a terminal operation.
from - the initial value of the index (inclusive)step - the step of the indexaction - the action to be performed on each elementpublic int reduce(int identity,
@NotNull
IntBinaryOperator op)
The identity value must be an identity for the accumulator
function. This means that for all x,
accumulator.apply(identity, x) is equal to x.
The accumulator function must be an associative function.
This is a terminal operation.
Example:
identity: 0 accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: 15
@NotNull public OptionalInt reduce(@NotNull IntBinaryOperator op)
OptionalInt
describing the reduced value, if any.
The op function must be an associative function.
This is a terminal operation.
op - an associative, non-interfering, stateless function for
combining two valuesreduce(int, IntBinaryOperator)@NotNull public int[] toArray()
This is a terminal operation.
@Nullable
public <R> R collect(@NotNull
Supplier<R> supplier,
@NotNull
ObjIntConsumer<R> accumulator)
supplier provided container by applying the given accumulation function.
This is a terminal operation.
R - the type of the resultsupplier - the supplier function that provides containeraccumulator - the accumulation functionStream.collect(com.annimon.stream.function.Supplier, com.annimon.stream.function.BiConsumer)public int sum()
@NotNull public OptionalInt min()
OptionalInt describing the minimum element of this
stream, or an empty optional if this stream is empty.
This is a terminal operation.
OptionalInt containing the minimum element of this
stream, or an empty OptionalInt if the stream is empty@NotNull public OptionalInt max()
OptionalInt describing the maximum element of this
stream, or an empty optional if this stream is empty.
This is a terminal operation.
OptionalInt containing the maximum element of this
stream, or an empty OptionalInt if the stream is emptypublic long count()
This is a terminal operation.
public boolean anyMatch(@NotNull
IntPredicate predicate)
false is returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
Example:
predicate: (a) -> a == 5 stream: [1, 2, 3, 4, 5] result: true predicate: (a) -> a == 5 stream: [5, 5, 5] result: true
predicate - a non-interfering stateless predicate to apply
to elements of this streamtrue if any elements of the stream match the provided
predicate, otherwise falsepublic boolean allMatch(@NotNull
IntPredicate predicate)
true is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
Example:
predicate: (a) -> a == 5 stream: [1, 2, 3, 4, 5] result: false predicate: (a) -> a == 5 stream: [5, 5, 5] result: true
predicate - a non-interfering stateless predicate to apply to
elements of this streamtrue if either all elements of the stream match the
provided predicate or the stream is empty, otherwise falsepublic boolean noneMatch(@NotNull
IntPredicate predicate)
true is
returned and the predicate is not evaluated.
This is a short-circuiting terminal operation.
Example:
predicate: (a) -> a == 5 stream: [1, 2, 3, 4, 5] result: false predicate: (a) -> a == 5 stream: [1, 2, 3] result: true
predicate - a non-interfering stateless predicate to apply to
elements of this streamtrue if either no elements of the stream match the
provided predicate or the stream is empty, otherwise false@NotNull public OptionalInt findFirst()
OptionalInt describing the first element of this
stream, or an empty OptionalInt if the stream is empty.
This is a short-circuiting terminal operation.
OptionalInt describing the first element of this stream,
or an empty OptionalInt if the stream is emptypublic int findFirstOrElse(int other)
other.
This is a short-circuiting terminal operation.
other - the value to be returned if stream is emptyother if stream is empty@NotNull public OptionalInt findLast()
OptionalInt class.
If stream is empty, returns OptionalInt.empty().
This is a short-circuiting terminal operation.
OptionalInt with the last element
or OptionalInt.empty() if the stream is emptypublic int single()
NoSuchElementException.
If stream contains more than one element, throws IllegalStateException.
This is a short-circuiting terminal operation.
Example:
stream: [] result: NoSuchElementException stream: [1] result: 1 stream: [1, 2, 3] result: IllegalStateException
java.util.NoSuchElementException - if stream is emptyjava.lang.IllegalStateException - if stream contains more than one element@NotNull public OptionalInt findSingle()
OptionalInt class.
If stream is empty, returns OptionalInt.empty().
If stream contains more than one element, throws IllegalStateException.
This is a short-circuiting terminal operation.
Example:
stream: [] result: OptionalInt.empty() stream: [1] result: OptionalInt.of(1) stream: [1, 2, 3] result: IllegalStateException
OptionalInt with single element or OptionalInt.empty() if stream is emptyjava.lang.IllegalStateException - if stream contains more than one element@NotNull public IntStream onClose(@NotNull java.lang.Runnable closeHandler)
This is an intermediate operation.
closeHandler - an action to execute when the stream is closedpublic void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseable