# BaseStream

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/java/util/stream/BaseStream#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/util/stream/BaseStream#inhmethods)  

# BaseStream

`
public


interface
BaseStream
`  
`


implements

`[AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)`


`

|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| java.util.stream.BaseStream\<T, S extends[java.util.stream.BaseStream](https://developer.android.com/reference/java/util/stream/BaseStream)\<T, S\>\> |

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known indirect subclasses [DoubleStream](https://developer.android.com/reference/java/util/stream/DoubleStream),[IntStream](https://developer.android.com/reference/java/util/stream/IntStream),[LongStream](https://developer.android.com/reference/java/util/stream/LongStream),[Stream](https://developer.android.com/reference/java/util/stream/Stream)\<T\> |---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------| | [DoubleStream](https://developer.android.com/reference/java/util/stream/DoubleStream) | A sequence of primitive double-valued elements supporting sequential and parallel aggregate operations. | | [IntStream](https://developer.android.com/reference/java/util/stream/IntStream)       | A sequence of primitive int-valued elements supporting sequential and parallel aggregate operations.    | | [LongStream](https://developer.android.com/reference/java/util/stream/LongStream)     | A sequence of primitive long-valued elements supporting sequential and parallel aggregate operations.   | | [Stream](https://developer.android.com/reference/java/util/stream/Stream)\<T\>        | A sequence of elements supporting sequential and parallel aggregate operations.                         | |

<br />

*** ** * ** ***

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](https://developer.android.com/reference/java/util/stream/Stream)and[IntStream](https://developer.android.com/reference/java/util/stream/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](https://developer.android.com/reference/java/util/stream/Stream)and the package documentation for[java.util.stream](https://developer.android.com/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.

<br />

**See also:**

- [Stream](https://developer.android.com/reference/java/util/stream/Stream)
- [IntStream](https://developer.android.com/reference/java/util/stream/IntStream)
- [LongStream](https://developer.android.com/reference/java/util/stream/LongStream)
- [DoubleStream](https://developer.android.com/reference/java/util/stream/DoubleStream)
- [java.util.stream](https://developer.android.com/reference/java/util/stream/package-summary)

## Summary

|                                                                                                                                                                          ### Public methods                                                                                                                                                                           ||
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void`                                                                              | ` `[close](https://developer.android.com/reference/java/util/stream/BaseStream#close())`() ` Closes this stream, causing all close handlers for this stream pipeline to be called.                                                                                     |
| ` abstract boolean`                                                                           | ` `[isParallel](https://developer.android.com/reference/java/util/stream/BaseStream#isParallel())`() ` Returns whether this stream, if a terminal operation were to be executed, would execute in parallel.                                                            |
| ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<T>`       | ` `[iterator](https://developer.android.com/reference/java/util/stream/BaseStream#iterator())`() ` Returns an iterator for the elements of this stream.                                                                                                                |
| ` abstract S`                                                                                 | ` `[onClose](https://developer.android.com/reference/java/util/stream/BaseStream#onClose(java.lang.Runnable))`(`[Runnable](https://developer.android.com/reference/java/lang/Runnable)` closeHandler) ` Returns an equivalent stream with an additional close handler. |
| ` abstract S`                                                                                 | ` `[parallel](https://developer.android.com/reference/java/util/stream/BaseStream#parallel())`() ` Returns an equivalent stream that is parallel.                                                                                                                      |
| ` abstract S`                                                                                 | ` `[sequential](https://developer.android.com/reference/java/util/stream/BaseStream#sequential())`() ` Returns an equivalent stream that is sequential.                                                                                                                |
| ` abstract `[Spliterator](https://developer.android.com/reference/java/util/Spliterator)`<T>` | ` `[spliterator](https://developer.android.com/reference/java/util/stream/BaseStream#spliterator())`() ` Returns a spliterator for the elements of this stream.                                                                                                        |
| ` abstract S`                                                                                 | ` `[unordered](https://developer.android.com/reference/java/util/stream/BaseStream#unordered())`() ` Returns an equivalent stream that is[unordered](https://developer.android.com/reference/java/util/stream/package-summary#Ordering).                               |

| ### Inherited methods |
|-----------------------|---|
| From interface` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Public methods

### close

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void close ()
```

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

<br />

**See also:**

- [AutoCloseable.close()](https://developer.android.com/reference/java/lang/AutoCloseable#close())  

### isParallel

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.

<br />

|                                   Returns                                    ||
|-----------|-------------------------------------------------------------------|
| `boolean` | `true`if this stream would execute in parallel if executed <br /> |

### iterator

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract Iterator<T> iterator ()
```

Returns an iterator for the elements of this stream.

This is a[terminal operation](https://developer.android.com/reference/java/util/stream/package-summary#StreamOps).

<br />

##### 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](https://developer.android.com/reference/java/util/Iterator)`<T>` | the element iterator for this stream <br /> |

### onClose

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract S onClose (Runnable closeHandler)
```

Returns an equivalent stream with an additional close handler. Close handlers are run when the[close()](https://developer.android.com/reference/java/util/stream/BaseStream#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](https://developer.android.com/reference/java/util/stream/package-summary#StreamOps).

<br />

|                                   Parameters                                   ||
|----------------|----------------------------------------------------------------|
| `closeHandler` | `Runnable`: A task to execute when the stream is closed <br /> |

|                                 Returns                                 ||
|-----|--------------------------------------------------------------------|
| `S` | a stream with a handler that is run if the stream is closed <br /> |

### parallel

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/java/util/stream/package-summary#StreamOps).

<br />

|            Returns            ||
|-----|--------------------------|
| `S` | a parallel stream <br /> |

### sequential

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/java/util/stream/package-summary#StreamOps).

<br />

|             Returns             ||
|-----|----------------------------|
| `S` | a sequential stream <br /> |

### spliterator

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract Spliterator<T> spliterator ()
```

Returns a spliterator for the elements of this stream.

This is a[terminal operation](https://developer.android.com/reference/java/util/stream/package-summary#StreamOps).

<br />

##### 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](https://developer.android.com/reference/java/util/Spliterator)`<T>` | the element spliterator for this stream <br /> |

### unordered

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract S unordered ()
```

Returns an equivalent stream that is[unordered](https://developer.android.com/reference/java/util/stream/package-summary#Ordering). 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](https://developer.android.com/reference/java/util/stream/package-summary#StreamOps).

<br />

|             Returns             ||
|-----|----------------------------|
| `S` | an unordered stream <br /> |