IntStream.Builder
Stay organized with collections
Save and categorize content based on your preferences.
A mutable builder for an IntStream
.
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()
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.
Public Method Summary
abstract
void
|
accept(int t)
Adds an element to the stream being built.
|
IntStream.Builder
|
add(int t)
Adds an element to the stream being built.
|
abstract
IntStream
|
build()
Builds the stream, transitioning this builder to the built state.
|
Public Methods
public
abstract
void
accept
(int t)
Adds an element to the stream being built.
Adds an element to the stream being built.
public
abstract
IntStream
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.
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\u003eIntStream.Builder\u003c/code\u003e allows you to create an \u003ccode\u003eIntStream\u003c/code\u003e by adding elements individually.\u003c/p\u003e\n"],["\u003cp\u003eIt has two phases: a building phase where you can add elements, and a built phase after calling \u003ccode\u003ebuild()\u003c/code\u003e, creating the \u003ccode\u003eIntStream\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eaccept(int)\u003c/code\u003e and \u003ccode\u003eadd(int)\u003c/code\u003e methods add elements to the builder during the building phase.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ebuild()\u003c/code\u003e creates the \u003ccode\u003eIntStream\u003c/code\u003e from the added elements and transitions the builder to the built state, preventing further modifications.\u003c/p\u003e\n"],["\u003cp\u003eAttempting to modify the builder after calling \u003ccode\u003ebuild()\u003c/code\u003e results in an \u003ccode\u003eIllegalStateException\u003c/code\u003e.\u003c/p\u003e\n"]]],["`IntStream.Builder` is a mutable builder for creating an `IntStream`. It has a building phase where elements are added via `accept(int t)` or `add(int t)`. Calling `build()` finalizes the stream, transitioning the builder to a built state, preventing further element addition. The `build()` method creates an ordered stream from the added elements. Attempting to add elements or call `build()` after the built state throws an `IllegalStateException`.\n"],null,["public static interface **IntStream.Builder** implements [IntConsumer](../../../../reference/java/util/function/IntConsumer.html) \nA mutable builder for an `IntStream`.\n\nA stream builder has a lifecycle, which starts in a building\nphase, during which elements can be added, and then transitions to a built\nphase, after which elements may not be added. The built phase\nbegins when the [build()](../../../../reference/java/util/stream/IntStream.Builder.html#build()) method is called, which creates an\nordered stream whose elements are the elements that were added to the\nstream builder, in the order they were added. \n\nSee Also\n\n- [IntStream.builder()](../../../../reference/java/util/stream/IntStream.html#builder()) \n\nPublic Method Summary\n\n|------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [accept](../../../../reference/java/util/stream/IntStream.Builder.html#accept(int))(int t) Adds an element to the stream being built. |\n| [IntStream.Builder](../../../../reference/java/util/stream/IntStream.Builder.html) | [add](../../../../reference/java/util/stream/IntStream.Builder.html#add(int))(int t) Adds an element to the stream being built. |\n| abstract [IntStream](../../../../reference/java/util/stream/IntStream.html) | [build](../../../../reference/java/util/stream/IntStream.Builder.html#build())() Builds the stream, transitioning this builder to the built state. |\n\nInherited Method Summary \nFrom interface [java.util.function.IntConsumer](../../../../reference/java/util/function/IntConsumer.html) \n\n|--------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [accept](../../../../reference/java/util/function/IntConsumer.html#accept(int))(int value) Performs this operation on the given argument. |\n| [IntConsumer](../../../../reference/java/util/function/IntConsumer.html) | [andThen](../../../../reference/java/util/function/IntConsumer.html#andThen(java.util.function.IntConsumer))([IntConsumer](../../../../reference/java/util/function/IntConsumer.html) after) Returns a composed `IntConsumer` that performs, in sequence, this operation followed by the `after` operation. |\n\nPublic Methods \n\npublic abstract void\n**accept**\n(int t) \nAdds an element to the stream being built. \n\nParameters\n\n| t | the input argument |\n|---|--------------------|\n\nThrows\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | if the builder has already transitioned to the built state |\n|-------------------------------------------------------------------------------------|------------------------------------------------------------|\n\npublic [IntStream.Builder](../../../../reference/java/util/stream/IntStream.Builder.html)\n**add**\n(int t) \nAdds an element to the stream being built. \n\nParameters\n\n| t | the element to add |\n|---|--------------------|\n\nReturns\n\n- `this` builder \n\nThrows\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | if the builder has already transitioned to the built state |\n|-------------------------------------------------------------------------------------|------------------------------------------------------------|\n\npublic abstract [IntStream](../../../../reference/java/util/stream/IntStream.html)\n**build**\n() \nBuilds the stream, transitioning this builder to the built state.\nAn `IllegalStateException` is thrown if there are further\nattempts to operate on the builder after it has entered the built\nstate. \n\nReturns\n\n- the built stream \n\nThrows\n\n| [IllegalStateException](../../../../reference/java/lang/IllegalStateException.html) | if the builder has already transitioned to the built state |\n|-------------------------------------------------------------------------------------|------------------------------------------------------------|"]]