BaseStream
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
DoubleStream |
A sequence of primitive double-valued elements supporting sequential and parallel
aggregate operations. |
IntStream |
A sequence of primitive int-valued elements supporting sequential and parallel
aggregate operations. |
LongStream |
A sequence of primitive long-valued elements supporting sequential and parallel
aggregate operations. |
Stream<T> |
A sequence of elements supporting sequential and parallel aggregate
operations. |
|
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.
Public Method Summary
abstract
void
|
close()
Closes this stream, causing all close handlers for this stream pipeline
to be called.
|
abstract
boolean
|
isParallel()
Returns whether this stream, if a terminal operation were to be executed,
would execute in parallel.
|
abstract
Iterator<T>
|
iterator()
Returns an iterator for the elements of this stream.
|
abstract
S
|
onClose( Runnable closeHandler)
Returns an equivalent stream with an additional close handler.
|
abstract
S
|
parallel()
Returns an equivalent stream that is parallel.
|
abstract
S
|
sequential()
Returns an equivalent stream that is sequential.
|
abstract
Spliterator<T>
|
spliterator()
Returns a spliterator for the elements of this stream.
|
abstract
S
|
|
Public Methods
public
abstract
void
close
()
Closes this stream, causing all close handlers for this stream pipeline
to be called.
public
abstract
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
true
if this stream would execute in parallel if executed
public
abstract
Iterator<T>
iterator
()
Returns
- the element iterator for this stream
public
abstract
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 |
A task to execute when the stream is closed |
Returns
- a stream with a handler that is run if the stream is closed
public
abstract
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.
public
abstract
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.
public
abstract
Spliterator<T>
spliterator
()
Returns
- the element spliterator for this stream
public
abstract
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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eBaseStream\u003c/code\u003e is the base interface for Java streams, supporting both sequential and parallel aggregate operations on sequences of elements.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for controlling stream execution, such as \u003ccode\u003eparallel()\u003c/code\u003e for parallel processing and \u003ccode\u003esequential()\u003c/code\u003e for sequential processing.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eBaseStream\u003c/code\u003e also includes methods for obtaining an iterator or spliterator for stream elements, and for adding close handlers to be executed when the stream is closed.\u003c/p\u003e\n"],["\u003cp\u003eSeveral specialized stream interfaces like \u003ccode\u003eStream\u003c/code\u003e, \u003ccode\u003eIntStream\u003c/code\u003e, \u003ccode\u003eLongStream\u003c/code\u003e, and \u003ccode\u003eDoubleStream\u003c/code\u003e inherit from \u003ccode\u003eBaseStream\u003c/code\u003e to handle different data types.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use aggregate operations like filtering and mapping on streams to process data efficiently.\u003c/p\u003e\n"]]],[],null,["public interface **BaseStream** implements [AutoCloseable](../../../../reference/java/lang/AutoCloseable.html) \n\n|---|---|---|\n| Known Indirect Subclasses [DoubleStream](../../../../reference/java/util/stream/DoubleStream.html), [IntStream](../../../../reference/java/util/stream/IntStream.html), [LongStream](../../../../reference/java/util/stream/LongStream.html), [Stream](../../../../reference/java/util/stream/Stream.html)\\\u003cT\\\u003e |--------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------| | [DoubleStream](../../../../reference/java/util/stream/DoubleStream.html) | A sequence of primitive double-valued elements supporting sequential and parallel aggregate operations. | | [IntStream](../../../../reference/java/util/stream/IntStream.html) | A sequence of primitive int-valued elements supporting sequential and parallel aggregate operations. | | [LongStream](../../../../reference/java/util/stream/LongStream.html) | A sequence of primitive long-valued elements supporting sequential and parallel aggregate operations. | | [Stream](../../../../reference/java/util/stream/Stream.html)\\\u003cT\\\u003e | A sequence of elements supporting sequential and parallel aggregate operations. | |||\n\nBase interface for streams, which are sequences of elements supporting\nsequential and parallel aggregate operations. The following example\nillustrates an aggregate operation using the stream types [Stream](../../../../reference/java/util/stream/Stream.html)\nand [IntStream](../../../../reference/java/util/stream/IntStream.html), computing the sum of the weights of the red widgets:\n\n int sum = widgets.stream()\n .filter(w -\u003e w.getColor() == RED)\n .mapToInt(w -\u003e w.getWeight())\n .sum();\n \nSee the class documentation for [Stream](../../../../reference/java/util/stream/Stream.html) and the package documentation for [java.util.stream](/j2objc/javadoc/jre/reference/java/util/stream/package-summary) for additional specification of streams, stream operations, stream pipelines, and parallelism, which governs the behavior of all stream types.\n\n\u003cbr /\u003e\n\nSee Also\n\n- [Stream](../../../../reference/java/util/stream/Stream.html)\n- [IntStream](../../../../reference/java/util/stream/IntStream.html)\n- [LongStream](../../../../reference/java/util/stream/LongStream.html)\n- [DoubleStream](../../../../reference/java/util/stream/DoubleStream.html)\n- [java.util.stream](/j2objc/javadoc/jre/reference/java/util/stream/package-summary) \n\nPublic Method Summary\n\n|-------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/util/stream/BaseStream.html#close())() Closes this stream, causing all close handlers for this stream pipeline to be called. |\n| abstract boolean | [isParallel](../../../../reference/java/util/stream/BaseStream.html#isParallel())() Returns whether this stream, if a terminal operation were to be executed, would execute in parallel. |\n| abstract [Iterator](../../../../reference/java/util/Iterator.html)\\\u003cT\\\u003e | [iterator](../../../../reference/java/util/stream/BaseStream.html#iterator())() Returns an iterator for the elements of this stream. |\n| abstract S | [onClose](../../../../reference/java/util/stream/BaseStream.html#onClose(java.lang.Runnable))([Runnable](../../../../reference/java/lang/Runnable.html) closeHandler) Returns an equivalent stream with an additional close handler. |\n| abstract S | [parallel](../../../../reference/java/util/stream/BaseStream.html#parallel())() Returns an equivalent stream that is parallel. |\n| abstract S | [sequential](../../../../reference/java/util/stream/BaseStream.html#sequential())() Returns an equivalent stream that is sequential. |\n| abstract [Spliterator](../../../../reference/java/util/Spliterator.html)\\\u003cT\\\u003e | [spliterator](../../../../reference/java/util/stream/BaseStream.html#spliterator())() Returns a spliterator for the elements of this stream. |\n| abstract S | [unordered](../../../../reference/java/util/stream/BaseStream.html#unordered())() Returns an equivalent stream that is [unordered](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#Ordering). |\n\nInherited Method Summary \nFrom interface [java.lang.AutoCloseable](../../../../reference/java/lang/AutoCloseable.html) \n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [close](../../../../reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |\n\nPublic Methods \n\npublic abstract void\n**close**\n() \nCloses this stream, causing all close handlers for this stream pipeline\nto be called. \n\nSee Also\n\n- [AutoCloseable.close()](../../../../reference/java/lang/AutoCloseable.html#close()) \n\npublic abstract boolean\n**isParallel**\n() \nReturns whether this stream, if a terminal operation were to be executed,\nwould execute in parallel. Calling this method after invoking an\nterminal stream operation method may yield unpredictable results. \n\nReturns\n\n- `true` if this stream would execute in parallel if executed \n\npublic abstract [Iterator](../../../../reference/java/util/Iterator.html)\\\u003cT\\\u003e\n**iterator**\n() \nReturns an iterator for the elements of this stream.\n\nThis is a [terminal\noperation](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#StreamOps). \n\nReturns\n\n- the element iterator for this stream \n\npublic abstract S\n**onClose**\n([Runnable](../../../../reference/java/lang/Runnable.html) closeHandler) \nReturns an equivalent stream with an additional close handler. Close\nhandlers are run when the [close()](../../../../reference/java/util/stream/BaseStream.html#close()) method\nis called on the stream, and are executed in the order they were\nadded. All close handlers are run, even if earlier close handlers throw\nexceptions. If any close handler throws an exception, the first\nexception thrown will be relayed to the caller of `close()`, with\nany remaining exceptions added to that exception as suppressed exceptions\n(unless one of the remaining exceptions is the same exception as the\nfirst exception, since an exception cannot suppress itself.) May\nreturn itself.\n\nThis is an [intermediate\noperation](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#StreamOps). \n\nParameters\n\n| closeHandler | A task to execute when the stream is closed |\n|--------------|---------------------------------------------|\n\nReturns\n\n- a stream with a handler that is run if the stream is closed \n\npublic abstract S\n**parallel**\n() \nReturns an equivalent stream that is parallel. May return\nitself, either because the stream was already parallel, or because\nthe underlying stream state was modified to be parallel.\n\nThis is an [intermediate\noperation](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#StreamOps). \n\nReturns\n\n- a parallel stream \n\npublic abstract S\n**sequential**\n() \nReturns an equivalent stream that is sequential. May return\nitself, either because the stream was already sequential, or because\nthe underlying stream state was modified to be sequential.\n\nThis is an [intermediate\noperation](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#StreamOps). \n\nReturns\n\n- a sequential stream \n\npublic abstract [Spliterator](../../../../reference/java/util/Spliterator.html)\\\u003cT\\\u003e\n**spliterator**\n() \nReturns a spliterator for the elements of this stream.\n\nThis is a [terminal\noperation](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#StreamOps). \n\nReturns\n\n- the element spliterator for this stream \n\npublic abstract S\n**unordered**\n() \nReturns an equivalent stream that is\n[unordered](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#Ordering). May return\nitself, either because the stream was already unordered, or because\nthe underlying stream state was modified to be unordered.\n\nThis is an [intermediate\noperation](/j2objc/javadoc/jre/reference/java/util/stream/package-summary#StreamOps). \n\nReturns\n\n- an unordered stream"]]