T
- The type of data item in the streampublic interface Stream<T> extends Iterator<T>, Iterable<T>
filter(Predicate)
and map(Function)
, and consuming
operations, such as forEach(Operation)
and Iterator.next()
.
Streams may be either bounded or infinite in length. Once an item has been extracted from a stream, it is said to be consumed and is no longer available for operations on the stream.
Modifier and Type | Method and Description |
---|---|
Stream<T> |
filter(Predicate<T> filter)
Transform the stream by creating a view that consists of only the items
that match the given
Predicate . |
void |
forEach(Operation<T> op)
Apply the given
Operation to each item in the stream. |
int |
forEach(Operation<T> operation,
int limit)
Apply the given
Operation to each item in the stream. |
void |
forEach(Operation<T> operation,
Predicate<T> stopPredicate)
Apply the given
Operation to each item in the stream. |
<R> Stream<R> |
map(Function<T,R> mapper)
Transform the stream by creating a new stream that transforms the items
in this stream with the given
Function . |
<R> Stream<R> |
map(MultiFunction<T,R> mapper)
Transform the stream by creating a new stream that transforms the items
in this stream with the given
Function . |
void |
parallelForEach(Operation<T> op)
Apply the given
Operation to each item in the stream, making use
of multiple threads. |
void |
parallelForEach(Operation<T> op,
ThreadPoolExecutor pool)
Apply the given
Operation to each item in the stream, making use
of multiple threads. |
<R> Stream<R> |
transform(Function<Stream<T>,Stream<R>> transform)
Transform the stream using the given function to transform the items in
this stream.
|
forEachRemaining, hasNext, next, remove
forEach, iterator, spliterator
void forEach(Operation<T> op)
Operation
to each item in the stream. Items are
presented to the Operation
in the order they appear in the
stream.
Note: for an unbounded stream, this method will never return unless some form of exception is raised.
op
- the Operation
to applyvoid forEach(Operation<T> operation, Predicate<T> stopPredicate)
Operation
to each item in the stream. Items are
presented to the Operation
in the order they appear in the
stream. The given Predicate
can be used to stop processing of the
stream once some condition is met.
Note: for an unbounded stream, this method will never return unless some form of exception is raised or the condition of the stopPredicate is met.
operation
- the Operation
to applystopPredicate
- a predicate representing a condition that once met causes
processing to stopint forEach(Operation<T> operation, int limit)
Operation
to each item in the stream. Items are
presented to the Operation
in the order they appear in the
stream. The given Predicate
can be used to stop processing of the
stream once some condition is met.
Note: for an unbounded stream, this method will never return unless some form of exception is raised or the condition of the stopPredicate is met.
operation
- the Operation
to applylimit
- the number of items to read from the streamvoid parallelForEach(Operation<T> op)
Operation
to each item in the stream, making use
of multiple threads. The order in which operations are performed on the
stream is not guaranteed.
This method is intended to be a shortcut to calling
Parallel.forEachUnpartitioned(Iterator, Operation)
.
Note: for an unbounded stream, this method will never return unless some form of exception is raised.
op
- the Operation
to applyvoid parallelForEach(Operation<T> op, ThreadPoolExecutor pool)
Operation
to each item in the stream, making use
of multiple threads. The order in which operations are performed on the
stream is not guaranteed.
This method is intended to be a shortcut to calling
Parallel.forEachUnpartitioned(Iterator, Operation, ThreadPoolExecutor)
.
Note: for an unbounded stream, this method will never return unless some form of exception is raised.
op
- the Operation
to applypool
- the thread pool.Stream<T> filter(Predicate<T> filter)
Predicate
.filter
- the predicate<R> Stream<R> map(Function<T,R> mapper)
Function
.mapper
- the function to apply<R> Stream<R> map(MultiFunction<T,R> mapper)
Function
.mapper
- the function to apply