Top Description Methods
java.util.stream

public Interface BaseStream<T, S extends BaseStream<T, S>>

extends AutoCloseable
Known Direct Subinterfaces
java.util.stream.DoubleStream, java.util.stream.IntStream, java.util.stream.LongStream, java.util.stream.Stream
Known Direct Implementers
java.util.stream.AbstractPipeline
Type Parameters
<T>
the type of the stream elements
<S>
the type of the stream implementing BaseStream
Imports
java.util.Iterator, .Spliterator

Base interface for streams, which are sequences of elements supporting sequential and parallel aggregate operations. The following example illustrates an aggregate operation using the stream types Stream and IntStream, computing the sum of the weights of the red widgets:
int sum = widgets.stream()
                     .filter(w -> w.getColor() == RED)
                     .mapToInt(w -> w.getWeight())
                     .sum();
See the class documentation for Stream and the package documentation for java.util.stream for additional specification of streams, stream operations, stream pipelines, and parallelism, which governs the behavior of all stream types.
Since
1.8
See Also
Stream, IntStream, LongStream, DoubleStream, java.util.stream

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares java.lang.AutoCloseable.close.

Closes this stream, causing all close handlers for this stream pipeline to be called.

public boolean

Returns:

true if this stream would execute in parallel if executed
isParallel
()

Returns whether this stream, if a terminal operation were to be executed, would execute in parallel.

public Iterator<T>

Returns:

the element iterator for this stream
iterator
()

Returns an iterator for the elements of this stream.

public S

Returns:

a stream with a handler that is run if the stream is closed
onClose
(Runnable
A task to execute when the stream is closed
closeHandler
)

Returns an equivalent stream with an additional close handler.

public S

Returns:

a parallel stream
parallel
()

Returns an equivalent stream that is parallel.

public S

Returns:

a sequential stream
sequential
()

Returns an equivalent stream that is sequential.

public Spliterator<T>

Returns:

the element spliterator for this stream
spliterator
()

Returns a spliterator for the elements of this stream.

public S

Returns:

an unordered stream
unordered
()

Returns an equivalent stream that is unordered.

Method Detail

closeback to summary
public void close()

Redeclares java.lang.AutoCloseable.close.

Closes this stream, causing all close handlers for this stream pipeline to be called.

Annotations
@Override
See Also
AutoCloseable#close()
isParallelback to summary
public boolean isParallel()

Returns whether this stream, if a terminal operation were to be executed, would execute in parallel. Calling this method after invoking an terminal stream operation method may yield unpredictable results.

Returns:boolean

true if this stream would execute in parallel if executed

iteratorback to summary
public Iterator<T> iterator()

Returns an iterator for the elements of this stream.

This is a terminal operation.

API Note

This operation is provided as an "escape hatch" to enable arbitrary client-controlled pipeline traversals in the event that the existing operations are not sufficient to the task.

Returns:Iterator<T>

the element iterator for this stream

onCloseback to summary
public S onClose(Runnable closeHandler)

Returns an equivalent stream with an additional close handler. Close handlers are run when the close() method is called on the stream, and are executed in the order they were added. All close handlers are run, even if earlier close handlers throw exceptions. If any close handler throws an exception, the first exception thrown will be relayed to the caller of close(), with any remaining exceptions added to that exception as suppressed exceptions (unless one of the remaining exceptions is the same exception as the first exception, since an exception cannot suppress itself.) May return itself.

This is an intermediate operation.

Parameters
closeHandler:Runnable

A task to execute when the stream is closed

Returns:S

a stream with a handler that is run if the stream is closed

parallelback to summary
public S parallel()

Returns an equivalent stream that is parallel. May return itself, either because the stream was already parallel, or because the underlying stream state was modified to be parallel.

This is an intermediate operation.

Returns:S

a parallel stream

sequentialback to summary
public S sequential()

Returns an equivalent stream that is sequential. May return itself, either because the stream was already sequential, or because the underlying stream state was modified to be sequential.

This is an intermediate operation.

Returns:S

a sequential stream

spliteratorback to summary
public Spliterator<T> spliterator()

Returns a spliterator for the elements of this stream.

This is a terminal operation.

API Note

This operation is provided as an "escape hatch" to enable arbitrary client-controlled pipeline traversals in the event that the existing operations are not sufficient to the task.

The returned spliterator should report the set of characteristics derived from the stream pipeline (namely the characteristics derived from the stream source spliterator and the intermediate operations). Implementations may report a sub-set of those characteristics. For example, it may be too expensive to compute the entire set for some or all possible stream pipelines.

Returns:Spliterator<T>

the element spliterator for this stream

unorderedback to summary
public S unordered()

Returns an equivalent stream that is unordered. May return itself, either because the stream was already unordered, or because the underlying stream state was modified to be unordered.

This is an intermediate operation.

Returns:S

an unordered stream