# Stream.Builder

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/Stream.Builder#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/util/stream/Stream.Builder#inhmethods)  

# Stream.Builder

`
public
static


interface
Stream.Builder
`  
`


implements

`[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<T>


`

|--------------------------------------|
| java.util.stream.Stream.Builder\<T\> |

<br />

*** ** * ** ***

A mutable builder for a`Stream`. This allows the creation of a`Stream`by generating elements individually and adding them to the`Builder`(without the copying overhead that comes from using an`ArrayList`as a temporary buffer.)

A stream builder has a lifecycle, which starts in a building phase, during which elements can be added, and then transitions to a built phase, after which elements may not be added. The built phase begins when the[build()](https://developer.android.com/reference/java/util/stream/Stream.Builder#build())method is called, which creates an ordered`Stream`whose elements are the elements that were added to the stream builder, in the order they were added.  
**See also:**

- [Stream.builder()](https://developer.android.com/reference/java/util/stream/Stream#builder())

## Summary

|                                                                                                                           ### Public methods                                                                                                                           ||
|----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void`                                                                                   | ` `[accept](https://developer.android.com/reference/java/util/stream/Stream.Builder#accept(T))`(T t) ` Adds an element to the stream being built.                  |
| ` default `[Builder](https://developer.android.com/reference/java/util/stream/Stream.Builder)`<T>` | ` `[add](https://developer.android.com/reference/java/util/stream/Stream.Builder#add(T))`(T t) ` Adds an element to the stream being built.                        |
| ` abstract `[Stream](https://developer.android.com/reference/java/util/stream/Stream)`<T>`         | ` `[build](https://developer.android.com/reference/java/util/stream/Stream.Builder#build())`() ` Builds the stream, transitioning this builder to the built state. |

| ### Inherited methods |
|-----------------------|---|
| From interface` `[java.util.function.Consumer](https://developer.android.com/reference/java/util/function/Consumer)` ` |-------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void`                                                                                | ` `[accept](https://developer.android.com/reference/java/util/function/Consumer#accept(T))`(T t) ` Performs this operation on the given argument.                                                                                                                                                                                                    | | ` default `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<T>` | ` `[andThen](https://developer.android.com/reference/java/util/function/Consumer#andThen(java.util.function.Consumer<?%20super%20T>))`(`[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<? super T> after) ` Returns a composed`Consumer`that performs, in sequence, this operation followed by the`after`operation. | ||

## Public methods

### accept

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

```
public abstract void accept (T t)
```

Adds an element to the stream being built.

<br />

|             Parameters              ||
|-----|--------------------------------|
| `t` | `T`: the input argument <br /> |

|                                                                            Throws                                                                            ||
|--------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the builder has already transitioned to the built state |

### add

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

```
public Builder<T> add (T t)
```

Adds an element to the stream being built.

<br />

##### Implementation Requirements:

- The default implementation behaves as if:  

      accept(t)
           return this;
       
|             Parameters              ||
|-----|--------------------------------|
| `t` | `T`: the element to add <br /> |

|                                                    Returns                                                    ||
|-----------------------------------------------------------------------------------------|----------------------|
| [Builder](https://developer.android.com/reference/java/util/stream/Stream.Builder)`<T>` | `this`builder <br /> |

|                                                                            Throws                                                                            ||
|--------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the builder has already transitioned to the built state |

### build

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

```
public abstract Stream<T> build ()
```

Builds the stream, transitioning this builder to the built state. An`IllegalStateException`is thrown if there are further attempts to operate on the builder after it has entered the built state.

<br />

|                                                 Returns                                                 ||
|--------------------------------------------------------------------------------|-------------------------|
| [Stream](https://developer.android.com/reference/java/util/stream/Stream)`<T>` | the built stream <br /> |

|                                                                            Throws                                                                            ||
|--------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the builder has already transitioned to the built state |