public final class DoubleStream
extends java.lang.Object
implements java.io.Closeable
double-valued elements supporting aggregate operations.Stream| Modifier and Type | Class and Description |
|---|---|
static interface |
DoubleStream.DoubleMapMultiConsumer
Represents an operation on two input arguments.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(DoublePredicate predicate)
Tests whether all elements match the given predicate.
|
boolean |
anyMatch(DoublePredicate predicate)
Tests whether all elements match the given predicate.
|
DoubleStream |
append(DoubleStream stream)
Appends given
DoubleStream to current and returns a new stream. |
OptionalDouble |
average()
Returns the average of elements in this stream.
|
Stream<java.lang.Double> |
boxed()
Returns a
Stream consisting of the elements of this stream,
each boxed to an Double. |
void |
close()
Causes close handler to be invoked if it exists.
|
<R> R |
collect(Supplier<R> supplier,
ObjDoubleConsumer<R> accumulator)
Collects elements to
supplier provided container by applying the given accumulation function. |
static DoubleStream |
concat(DoubleStream a,
DoubleStream b)
Lazily concatenates two streams.
|
static DoubleStream |
concat(DoubleStream a,
DoubleStream b,
DoubleStream... rest)
Lazily concatenates three or more streams.
|
long |
count()
Returns the count of elements in this stream.
|
<R> R |
custom(Function<DoubleStream,R> function)
Applies custom operator on stream.
|
DoubleStream |
distinct()
Returns a stream consisting of the distinct elements of this stream.
|
DoubleStream |
dropWhile(DoublePredicate predicate)
Drops elements while the predicate is true and returns the rest.
|
static DoubleStream |
empty()
Returns an empty stream.
|
DoubleStream |
filter(DoublePredicate predicate)
Returns
DoubleStream with elements that satisfy the given predicate. |
DoubleStream |
filterIndexed(IndexedDoublePredicate predicate)
Returns a
DoubleStream with elements that satisfy the given IndexedDoublePredicate. |
DoubleStream |
filterIndexed(int from,
int step,
IndexedDoublePredicate predicate)
Returns a
DoubleStream with elements that satisfy the given IndexedDoublePredicate. |
DoubleStream |
filterNot(DoublePredicate predicate)
Returns
DoubleStream with elements that does not satisfy the given predicate. |
OptionalDouble |
findFirst()
Returns the first element wrapped by
OptionalDouble class. |
double |
findFirstOrElse(double other)
Returns the first element if stream is not empty,
otherwise returns
other. |
OptionalDouble |
findLast()
Returns the last element wrapped by
OptionalDouble class. |
OptionalDouble |
findSingle()
Returns the single element wrapped by
OptionalDouble class. |
DoubleStream |
flatMap(DoubleFunction<? extends DoubleStream> 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(DoubleConsumer action)
Performs an action for each element of this stream.
|
void |
forEachIndexed(IndexedDoubleConsumer action)
Performs the given indexed action on each element.
|
void |
forEachIndexed(int from,
int step,
IndexedDoubleConsumer action)
Performs the given indexed action on each element.
|
static DoubleStream |
generate(DoubleSupplier s)
Creates a
DoubleStream by elements that generated by DoubleSupplier. |
static DoubleStream |
iterate(double seed,
DoublePredicate predicate,
DoubleUnaryOperator op)
Creates an
DoubleStream by iterative application DoubleUnaryOperator function
to an initial element seed, conditioned on satisfying the supplied predicate. |
static DoubleStream |
iterate(double seed,
DoubleUnaryOperator f)
Creates a
DoubleStream by iterative application DoubleUnaryOperator function
to an initial element seed. |
PrimitiveIterator.OfDouble |
iterator()
Returns internal
DoubleStream iterator. |
DoubleStream |
limit(long maxSize)
Returns a stream consisting of the elements of this stream, truncated
to be no longer than
maxSize in length. |
DoubleStream |
map(DoubleUnaryOperator mapper)
Returns an
DoubleStream consisting of the results of applying the given
function to the elements of this stream. |
DoubleStream |
mapIndexed(IndexedDoubleUnaryOperator mapper)
Returns a
DoubleStream with elements that obtained
by applying the given IndexedDoubleUnaryOperator. |
DoubleStream |
mapIndexed(int from,
int step,
IndexedDoubleUnaryOperator mapper)
Returns a
DoubleStream with elements that obtained
by applying the given IndexedDoubleUnaryOperator. |
DoubleStream |
mapMulti(DoubleStream.DoubleMapMultiConsumer 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.
|
IntStream |
mapToInt(DoubleToIntFunction mapper)
Returns an
IntStream consisting of the results of applying the given
function to the elements of this stream. |
LongStream |
mapToLong(DoubleToLongFunction mapper)
Returns an
LongStream consisting of the results of applying the given
function to the elements of this stream. |
<R> Stream<R> |
mapToObj(DoubleFunction<? extends R> mapper)
Returns a
Stream consisting of the results of applying the given
function to the elements of this stream. |
OptionalDouble |
max()
Returns an
OptionalDouble describing the maximum element of this
stream, or an empty optional if this stream is empty. |
OptionalDouble |
min()
Returns an
OptionalDouble describing the minimum element of this
stream, or an empty optional if this stream is empty. |
boolean |
noneMatch(DoublePredicate predicate)
Tests whether no elements match the given predicate.
|
static DoubleStream |
of(double... values)
Creates a
DoubleStream from the specified values. |
static DoubleStream |
of(double t)
Returns stream which contains single element passed as param
|
static DoubleStream |
of(PrimitiveIterator.OfDouble iterator)
Creates a
DoubleStream from PrimitiveIterator.OfDouble. |
DoubleStream |
onClose(java.lang.Runnable closeHandler)
Adds close handler to the current stream.
|
DoubleStream |
peek(DoubleConsumer action)
Performs provided action on each element.
|
DoubleStream |
prepend(DoubleStream stream)
Prepends given
DoubleStream to current and returns a new stream. |
OptionalDouble |
reduce(DoubleBinaryOperator accumulator)
Performs a reduction on the elements of this stream, using an
associative accumulation function, and returns an
OptionalDouble
describing the reduced value, if any. |
double |
reduce(double identity,
DoubleBinaryOperator accumulator)
Performs a reduction on the elements of this stream, using the provided
identity value and an associative accumulation function, and returns the
reduced value.
|
DoubleStream |
sample(int stepWidth)
Samples the
DoubleStream by emitting every n-th element. |
DoubleStream |
scan(DoubleBinaryOperator accumulator)
Returns a
DoubleStream produced by iterative application of a accumulation function
to reduction value and next element of the current stream. |
DoubleStream |
scan(double identity,
DoubleBinaryOperator accumulator)
Returns a
DoubleStream produced by iterative application of a accumulation function
to an initial element identity and next element of the current stream. |
double |
single()
Returns the single element of stream.
|
DoubleStream |
skip(long n)
Skips first
n elements and returns DoubleStream with remaining elements. |
DoubleStream |
sorted()
Returns a stream consisting of the elements of this stream in sorted order.
|
DoubleStream |
sorted(java.util.Comparator<java.lang.Double> comparator)
Returns a stream consisting of the elements of this stream
in sorted order as determinated by provided
Comparator. |
double |
sum()
Returns the sum of elements in this stream.
|
DoubleStream |
takeUntil(DoublePredicate stopPredicate)
Takes elements while the predicate returns
false. |
DoubleStream |
takeWhile(DoublePredicate predicate)
Takes elements while the predicate returns
true. |
double[] |
toArray()
Returns an array containing the elements of this stream.
|
@NotNull public static DoubleStream empty()
@NotNull public static DoubleStream of(@NotNull PrimitiveIterator.OfDouble iterator)
DoubleStream from PrimitiveIterator.OfDouble.iterator - the iterator with elements to be passed to streamDoubleStreamjava.lang.NullPointerException - if iterator is null@NotNull public static DoubleStream of(@NotNull double... values)
DoubleStream from the specified values.values - the elements of the new streamjava.lang.NullPointerException - if values is null@NotNull public static DoubleStream of(double t)
t - element of the stream@NotNull public static DoubleStream generate(@NotNull DoubleSupplier s)
DoubleStream by elements that generated by DoubleSupplier.s - the DoubleSupplier for generated elementsDoubleStreamjava.lang.NullPointerException - if s is null@NotNull public static DoubleStream iterate(double seed, @NotNull DoubleUnaryOperator f)
DoubleStream by iterative application DoubleUnaryOperator function
to an initial element seed. Produces DoubleStream consisting of
seed, f(seed), f(f(seed)), etc.
The first element (position 0) in the DoubleStream 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 elementDoubleStreamjava.lang.NullPointerException - if f is null@NotNull public static DoubleStream iterate(double seed, @NotNull DoublePredicate predicate, @NotNull DoubleUnaryOperator op)
DoubleStream by iterative application DoubleUnaryOperator function
to an initial element seed, conditioned on satisfying the supplied predicate.
Example:
seed: 0.0 predicate: (a) -> a < 0.2 f: (a) -> a + 0.05 result: [0.0, 0.05, 0.1, 0.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 DoubleStream concat(@NotNull DoubleStream a, @NotNull DoubleStream 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 DoubleStream concat(@NotNull DoubleStream a, @NotNull DoubleStream b, @NotNull DoubleStream... 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.OfDouble iterator()
DoubleStream iterator.DoubleStream iterator.@Nullable
public <R> R custom(@NotNull
Function<DoubleStream,R> function)
DoubleStream for intermediate operations,
or any value for terminal operation.
Operator examples:
// Intermediate operator
public class Zip implements Function<DoubleStream, DoubleStream> {
private final DoubleStream secondStream;
private final DoubleBinaryOperator combiner;
public Zip(DoubleStream secondStream, DoubleBinaryOperator combiner) {
this.secondStream = secondStream;
this.combiner = combiner;
}
@Override
public DoubleStream apply(DoubleStream firstStream) {
final PrimitiveIterator.OfDouble it1 = firstStream.iterator();
final PrimitiveIterator.OfDouble it2 = secondStream.iterator();
return DoubleStream.of(new PrimitiveIterator.OfDouble() {
@Override
public boolean hasNext() {
return it1.hasNext() && it2.hasNext();
}
@Override
public double nextDouble() {
return combiner.applyAsDouble(it1.nextDouble(), it2.nextDouble());
}
});
}
}
// Intermediate operator based on existing stream operators
public class SkipAndLimit implements UnaryOperator<DoubleStream> {
private final int skip, limit;
public SkipAndLimit(int skip, int limit) {
this.skip = skip;
this.limit = limit;
}
@Override
public DoubleStream apply(DoubleStream stream) {
return stream.skip(skip).limit(limit);
}
}
// Terminal operator
public class DoubleSummaryStatistics implements Function<DoubleStream, double[]> {
@Override
public double[] apply(DoubleStream stream) {
long count = 0;
double sum = 0;
final PrimitiveIterator.OfDouble it = stream.iterator();
while (it.hasNext()) {
count++;
sum += it.nextDouble();
}
double average = (count == 0) ? 0 : (sum / (double) count);
return new double[] {count, sum, average};
}
}
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.Double> boxed()
Stream consisting of the elements of this stream,
each boxed to an Double.
This is an lazy intermediate operation.
Stream consistent of the elements of this stream,
each boxed to an Double@NotNull public DoubleStream prepend(@NotNull DoubleStream stream)
DoubleStream to current and returns a new stream.
This is similar to DoubleStream.concat(stream, this)
Example:
current: [1, 2, 3] stream: [4, 5, 6] result: [4, 5, 6, 1, 2, 3]
stream - the stream to prependconcat(DoubleStream, DoubleStream)@NotNull public DoubleStream append(@NotNull DoubleStream stream)
DoubleStream to current and returns a new stream.
This is similar to DoubleStream.concat(this, stream)
Example:
current: [1, 2, 3] stream: [4, 5, 6] result: [1, 2, 3, 4, 5, 6]
stream - the stream to appendconcat(DoubleStream, DoubleStream)@NotNull public DoubleStream filter(@NotNull DoublePredicate predicate)
DoubleStream with elements that satisfy the given predicate.
This is an intermediate operation.
Example:
predicate: (a) -> a > 2 stream: [1, 2, 3, 4, -8, 0, 11] result: [3, 4, 11]
predicate - the predicate used to filter elements@NotNull public DoubleStream filterIndexed(@NotNull IndexedDoublePredicate predicate)
DoubleStream with elements that satisfy the given IndexedDoublePredicate.
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 IndexedDoublePredicate used to filter elements@NotNull public DoubleStream filterIndexed(int from, int step, @NotNull IndexedDoublePredicate predicate)
DoubleStream with elements that satisfy the given IndexedDoublePredicate.
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 IndexedDoublePredicate used to filter elements@NotNull public DoubleStream filterNot(@NotNull DoublePredicate predicate)
DoubleStream with elements that does not satisfy the given predicate.
This is an intermediate operation.
predicate - the predicate used to filter elements@NotNull public DoubleStream map(@NotNull DoubleUnaryOperator mapper)
DoubleStream 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 - the mapper function used to apply to each elementStream.map(com.annimon.stream.function.Function)@NotNull public DoubleStream mapIndexed(@NotNull IndexedDoubleUnaryOperator mapper)
DoubleStream with elements that obtained
by applying the given IndexedDoubleUnaryOperator.
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 DoubleStream mapIndexed(int from, int step, @NotNull IndexedDoubleUnaryOperator mapper)
DoubleStream with elements that obtained
by applying the given IndexedDoubleUnaryOperator.
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 DoubleFunction<? 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 IntStream mapToInt(@NotNull DoubleToIntFunction mapper)
IntStream 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 elementIntStream@NotNull public LongStream mapToLong(@NotNull DoubleToLongFunction 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 elementLongStream@NotNull public DoubleStream flatMap(@NotNull DoubleFunction<? extends DoubleStream> 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 - the mapper function used to apply to each elementStream.flatMap(com.annimon.stream.function.Function)@NotNull public DoubleStream mapMulti(@NotNull DoubleStream.DoubleMapMultiConsumer 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.DoubleFunction)@NotNull public DoubleStream distinct()
This is a stateful intermediate operation.
Example:
stream: [1, 4, 2, 3, 3, 4, 1] result: [1, 4, 2, 3]
@NotNull public DoubleStream sorted()
This is a stateful intermediate operation.
Example:
stream: [3, 4, 1, 2] result: [1, 2, 3, 4]
@NotNull public DoubleStream sorted(@Nullable java.util.Comparator<java.lang.Double> comparator)
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 elementsDoubleStream@NotNull public DoubleStream sample(int stepWidth)
DoubleStream 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 widthDoubleStreamjava.lang.IllegalArgumentException - if stepWidth is zero or negativeStream.sample(int)@NotNull public DoubleStream peek(@NotNull DoubleConsumer action)
This is an intermediate operation.
action - the action to be performed on each element@NotNull public DoubleStream scan(@NotNull DoubleBinaryOperator accumulator)
DoubleStream produced by iterative application of a accumulation function
to reduction value and next element of the current stream.
Produces a DoubleStream 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 DoubleStream scan(double identity, @NotNull DoubleBinaryOperator accumulator)
DoubleStream produced by iterative application of a accumulation function
to an initial element identity and next element of the current stream.
Produces a DoubleStream 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 DoubleStream takeWhile(@NotNull DoublePredicate 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 elementsDoubleStream@NotNull public DoubleStream takeUntil(@NotNull DoublePredicate 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 elementsDoubleStream@NotNull public DoubleStream dropWhile(@NotNull DoublePredicate 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 elementsDoubleStream@NotNull public DoubleStream 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 DoubleStream skip(long n)
n elements and returns DoubleStream with remaining elements.
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 elements to skipjava.lang.IllegalArgumentException - if n is negativepublic void forEach(@NotNull
DoubleConsumer action)
This is a terminal operation.
action - the action to be performed on each elementpublic void forEachIndexed(@NotNull
IndexedDoubleConsumer action)
This is a terminal operation.
action - the action to be performed on each elementpublic void forEachIndexed(int from,
int step,
@NotNull
IndexedDoubleConsumer 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 double reduce(double identity,
@NotNull
DoubleBinaryOperator accumulator)
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 OptionalDouble reduce(@NotNull DoubleBinaryOperator accumulator)
OptionalDouble
describing the reduced value, if any.
The accumulator function must be an associative function.
This is a terminal operation.
accumulator - the accumulation functionreduce(com.annimon.stream.function.DoubleBinaryOperator)@NotNull public double[] toArray()
This is a terminal operation.
@Nullable
public <R> R collect(@NotNull
Supplier<R> supplier,
@NotNull
ObjDoubleConsumer<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 double sum()
@NotNull public OptionalDouble min()
OptionalDouble describing the minimum element of this
stream, or an empty optional if this stream is empty.
This is a terminal operation.
@NotNull public OptionalDouble max()
OptionalDouble describing the maximum element of this
stream, or an empty optional if this stream is empty.
This is a terminal operation.
public long count()
This is a terminal operation.
@NotNull public OptionalDouble average()
This is a terminal operation.
public boolean anyMatch(@NotNull
DoublePredicate 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 - the predicate used to match elementstrue if any elements of the stream match the provided
predicate, otherwise falsepublic boolean allMatch(@NotNull
DoublePredicate 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 - the predicate used to match elementstrue if either all elements of the stream match the
provided predicate or the stream is empty, otherwise falsepublic boolean noneMatch(@NotNull
DoublePredicate 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 - the predicate used to match elementstrue if either no elements of the stream match the
provided predicate or the stream is empty, otherwise false@NotNull public OptionalDouble findFirst()
OptionalDouble class.
If stream is empty, returns OptionalDouble.empty().
This is a short-circuiting terminal operation.
OptionalDouble with first element
or OptionalDouble.empty() if stream is emptypublic double findFirstOrElse(double 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 OptionalDouble findLast()
OptionalDouble class.
If stream is empty, returns OptionalDouble.empty().
This is a short-circuiting terminal operation.
OptionalDouble with the last element
or OptionalDouble.empty() if the stream is emptypublic double 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 OptionalDouble findSingle()
OptionalDouble class.
If stream is empty, returns OptionalDouble.empty().
If stream contains more than one element, throws IllegalStateException.
This is a short-circuiting terminal operation.
Example:
stream: [] result: OptionalDouble.empty() stream: [1] result: OptionalDouble.of(1) stream: [1, 2, 3] result: IllegalStateException
OptionalDouble with single element
or OptionalDouble.empty() if stream is emptyjava.lang.IllegalStateException - if stream contains more than one element@NotNull public DoubleStream 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