Java IntStream Methods

The java.util.stream.IntStream interface provides a sequence of primitive int-valued elements supporting sequential and parallel aggregate operations. Here are some of the commonly used methods:

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.
asDoubleStream() Returns a DoubleStream consisting of the elements of this stream, converted to double.
asLongStream() Returns a LongStream consisting of the elements of this stream, converted to long.
average() Returns an OptionalDouble describing the arithmetic mean of elements of this stream.
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 IntStream.
filter() Returns a stream consisting of the elements of this stream that match the given predicate.
findAny() Returns an OptionalInt describing some element of the stream, or an empty OptionalInt if the stream is empty.
findFirst() Returns an OptionalInt describing the first element of the stream, or an empty OptionalInt if the stream is empty.
flatMap() 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.
forEach() Performs an action for each element of the stream.
limit() Returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.
map() Returns a stream consisting of the results of applying the given function to the elements of this stream.
mapToDouble() Returns a DoubleStream 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 OptionalInt describing the maximum element of this stream, or an empty OptionalInt if the stream is empty.
min() Returns an OptionalInt describing the minimum element of this stream, or an empty OptionalInt if the stream is empty.
noneMatch() Returns whether no elements of this stream match the provided predicate.
of() Returns a sequential ordered stream whose elements are the specified values.
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.
range() Returns a sequential ordered IntStream from startInclusive (inclusive) to endExclusive (exclusive) by an incremental step of 1.
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 in sorted order.
sum() Returns the sum of elements in this stream.

In conclusion, the java.util.stream.IntStream interface provides a comprehensive set of methods to perform various operations on streams of primitive int-valued elements. These methods offer flexibility in processing and manipulating stream elements effectively. For more detailed information, refer to the official Java Documentation.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top