The IntStream
interface in Java provides a stream of primitive int values. It is a part of the Java Stream API which allows developers to perform various functional-style operations on streams of elements, such as filtering, mapping, and reducing.
This guide covers various methods available in the IntStream
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 integer streams, making it a versatile tool for data processing in Java.
For more detailed information, please refer to the official Java SE Documentation.
Java IntStream Interface Methods
The table below contains various methods of the Java IntStream
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. |
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, 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 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 this stream, or an empty OptionalInt if the stream is empty. |
flatMap() | Returns an IntStream 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 an IntStream 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, sorted according to natural order. |
sum() | Returns the sum of elements in this stream. |
Comments
Post a Comment
Leave Comment