IntStream class abstract
A sequence of primitive int
-valued elements supporting sequential and parallel
aggregate operations.
This is the int
primitive specialization of BaseStream. It supports
fluent-style functional operations such as map
, filter
, reduce
,
and terminal operations for processing or collecting data.
Example Usage
// Create an IntStream from a range
final sum = IntStream.range(1, 10)
.filter((n) => n % 2 == 0)
.sum();
print(sum); // 20
// Statistical operations
final stats = IntStream.of([1, 2, 3, 4, 5])
.summaryStatistics();
print('Average: ${stats.average}');
print('Max: ${stats.max}');
// Complex transformations
final result = IntStream.range(1, 100)
.filter((n) => n % 3 == 0)
.map((n) => n * n)
.limit(5)
.toList();
- Inheritance
-
- Object
- BaseStream<
int, IntStream> - IntStream
Constructors
- IntStream()
-
A sequence of primitive
int
-valued elements supporting sequential and parallel aggregate operations. - IntStream.empty()
-
Creates an empty IntStream.
factory
-
IntStream.of(Iterable<
int> values) -
Creates an IntStream from the given values.
factory
- IntStream.range(int startInclusive, int endExclusive)
-
Creates an IntStream from a range of integers.
factory
- IntStream.rangeClosed(int startInclusive, int endInclusive)
-
Creates an IntStream from a closed range of integers.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
allMatch(
bool predicate(int)) → bool -
Returns
true
if all elements match the predicate. -
anyMatch(
bool predicate(int)) → bool -
Returns
true
if any elements match the predicate. -
asDoubleStream(
) → DoubleStream -
Converts this
IntStream
to aDoubleStream
. -
average(
) → double - Returns the arithmetic mean of values in the stream.
-
close(
) → void -
Closes this stream, causing all close handlers for this stream pipeline
to be called.
inherited
-
collect(
) → List< int> -
Returns a list containing the elements of this stream.
inherited
-
count(
) → int - Returns the count of elements in the stream.
-
distinct(
) → IntStream - Returns a stream with duplicate elements removed.
-
dropWhile(
bool predicate(int)) → IntStream -
Drops elements from the stream while the predicate returns
true
, then returns the remaining elements. -
filter(
bool predicate(int)) → IntStream - Returns a stream consisting of elements that match the given predicate.
-
findAny(
) → Optional< int> - Returns any element from the stream, which may be useful in parallel contexts.
-
findFirst(
) → Optional< int> - Returns the first element of the stream, if present.
-
flatMap(
IntStream mapper(int)) → IntStream - Returns a stream consisting of the results of replacing each element with the contents of a mapped stream.
-
forEach(
void action(int)) → void - Performs the given action for each element of the stream.
-
forEachOrdered(
void action(int)) → void - Performs the given action for each element, respecting the encounter order.
-
isParallel(
) → bool -
Returns whether this stream, if a terminal operation were to be executed,
would execute in parallel.
inherited
-
iterable(
) → Iterable< int> -
Returns an iterable for the elements of this stream.
inherited
-
iterator(
) → Iterator< int> -
Returns an iterator for the elements of this stream.
inherited
-
limit(
int maxSize) → IntStream -
Truncates the stream to be no longer than
maxSize
. -
map(
int mapper(int)) → IntStream - Returns a stream consisting of the results of applying the given function to the elements of this stream.
-
mapToDouble(
double mapper(int)) → DoubleStream -
Returns a
DoubleStream
consisting of the results of applying the given function to the elements of this stream. -
max(
) → Optional< int> - Returns the maximum value as an Optional, or empty if the stream is empty.
-
min(
) → Optional< int> - Returns the minimum value as an Optional, or empty if the stream is empty.
-
noneMatch(
bool predicate(int)) → bool -
Returns
true
if no elements match the predicate. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onClose(
void closeHandler()) → IntStream -
Returns an equivalent stream with an additional close handler.
inherited
-
parallel(
) → IntStream -
Returns an equivalent stream that is parallel.
inherited
-
peek(
void action(int)) → IntStream - Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as they are consumed.
-
reduce(
int identity, int op(int, int)) → int - Performs a reduction on the elements using the given identity and associative accumulation function.
-
reduceOptional(
int op(int, int)) → Optional< int> - Performs a reduction and returns an Optional of the result.
-
sequential(
) → IntStream -
Returns an equivalent stream that is sequential.
inherited
-
skip(
int n) → IntStream -
Skips the first
n
elements of the stream. -
sorted(
) → IntStream - Returns a stream with elements sorted in natural ascending order.
-
sum(
) → int - Returns the sum of the elements.
-
takeWhile(
bool predicate(int)) → IntStream -
Returns a stream consisting of the elements taken from this stream
until the predicate returns
false
. -
toList(
) → List< int> - Collects the elements into a List.
-
toString(
) → String -
A string representation of this object.
inherited
-
unordered(
) → IntStream -
Returns an equivalent stream that is unordered.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited