Java DoubleStream Methods

The DoubleStream interface in Java is a part of the Java Stream API, which allows for functional-style operations on streams of elements. Specifically, DoubleStream is used for sequences of primitive double values. This interface includes a variety of methods for performing calculations, filtering, and transforming data efficiently.

This guide covers various methods available in the DoubleStream interface. Each method is described in simple terms to help beginners understand how to use them. These methods enable a wide range of operations on double streams, making it a powerful tool for handling numerical data in Java.

For more detailed information, please refer to the official Java SE Documentation

Java DoubleStream Interface Methods

The table below contains various methods of the Java DoubleStream interface, each with a link to a detailed explanation, examples, and real-world uses. Click on the method names to learn more about how to use them effectively in your applications.

Method Description
allMatch() Returns whether all elements of this stream match the provided predicate.
anyMatch() Returns whether any elements of this stream match the provided predicate.
average() Returns an OptionalDouble describing the arithmetic mean of elements of this stream, or an empty optional if the stream is empty.
collect() Performs a mutable reduction operation on the elements of this stream using a Collector.
concat() Creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream.
count() Returns the count of elements in this stream.
distinct() Returns a stream consisting of the distinct elements of this stream.
empty() Returns an empty sequential DoubleStream.
filter() Returns a stream consisting of the elements of this stream that match the given predicate.
findAny() Returns an OptionalDouble describing some element of the stream, or an empty OptionalDouble if the stream is empty.
findFirst() Returns an OptionalDouble describing the first element of this stream, or an empty OptionalDouble if the stream is empty.
flatMap() Returns a DoubleStream 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.
forEach() Performs an action for each element of this stream.
limit() Returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.
map() Returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.
mapToInt() Returns an IntStream consisting of the results of applying the given function to the elements of this stream.
mapToLong() Returns a LongStream consisting of the results of applying the given function to the elements of this stream.
max() Returns an OptionalDouble describing the maximum element of this stream, or an empty OptionalDouble if the stream is empty.
min() Returns an OptionalDouble describing the minimum element of this stream, or an empty OptionalDouble if the stream is empty.
of() Returns a sequential ordered stream whose elements are the specified values.
noneMatch() Returns whether no elements of this stream match the provided predicate.
reduce() Performs a reduction on the elements of this stream, using an associative accumulation function, and returns an OptionalDouble describing the reduced value, if any.
peek() 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.
skip() Returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.
sorted() Returns a stream consisting of the elements of this stream, sorted according to natural order.
sum() Returns the sum of elements in this stream.

References:

Comments