LongStream.Builder
Stay organized with collections
Save and categorize content based on your preferences.
A mutable builder for a LongStream
.
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
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(long t)
Adds an element to the stream being built.
|
LongStream.Builder
|
add(long t)
Adds an element to the stream being built.
|
abstract
LongStream
|
build()
Builds the stream, transitioning this builder to the built state.
|
Public Methods
public
abstract
void
accept
(long t)
Adds an element to the stream being built.
Adds an element to the stream being built.
public
abstract
LongStream
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\u003eLongStream.Builder\u003c/code\u003e is used to create a \u003ccode\u003eLongStream\u003c/code\u003e by adding elements and then building the stream.\u003c/p\u003e\n"],["\u003cp\u003eThe builder transitions to a "built" state after \u003ccode\u003ebuild()\u003c/code\u003e is called, preventing further element additions.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eaccept(long)\u003c/code\u003e and \u003ccode\u003eadd(long)\u003c/code\u003e methods add elements to the stream being built, while \u003ccode\u003ebuild()\u003c/code\u003e creates the final \u003ccode\u003eLongStream\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCalling builder methods after \u003ccode\u003ebuild()\u003c/code\u003e results in an \u003ccode\u003eIllegalStateException\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["public static interface **LongStream.Builder** implements [LongConsumer](../../../../reference/java/util/function/LongConsumer.html) \nA mutable builder for a `LongStream`.\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 begins\nbegins when the [build()](../../../../reference/java/util/stream/LongStream.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- [LongStream.builder()](../../../../reference/java/util/stream/LongStream.html#builder()) \n\nPublic Method Summary\n\n|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [accept](../../../../reference/java/util/stream/LongStream.Builder.html#accept(long))(long t) Adds an element to the stream being built. |\n| [LongStream.Builder](../../../../reference/java/util/stream/LongStream.Builder.html) | [add](../../../../reference/java/util/stream/LongStream.Builder.html#add(long))(long t) Adds an element to the stream being built. |\n| abstract [LongStream](../../../../reference/java/util/stream/LongStream.html) | [build](../../../../reference/java/util/stream/LongStream.Builder.html#build())() Builds the stream, transitioning this builder to the built state. |\n\nInherited Method Summary \nFrom interface [java.util.function.LongConsumer](../../../../reference/java/util/function/LongConsumer.html) \n\n|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [accept](../../../../reference/java/util/function/LongConsumer.html#accept(long))(long value) Performs this operation on the given argument. |\n| [LongConsumer](../../../../reference/java/util/function/LongConsumer.html) | [andThen](../../../../reference/java/util/function/LongConsumer.html#andThen(java.util.function.LongConsumer))([LongConsumer](../../../../reference/java/util/function/LongConsumer.html) after) Returns a composed `LongConsumer` that performs, in sequence, this operation followed by the `after` operation. |\n\nPublic Methods \n\npublic abstract void\n**accept**\n(long 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 [LongStream.Builder](../../../../reference/java/util/stream/LongStream.Builder.html)\n**add**\n(long 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 [LongStream](../../../../reference/java/util/stream/LongStream.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|-------------------------------------------------------------------------------------|------------------------------------------------------------|"]]