buildString
Builds an immutable String using an initially empty StringBuilder.
The action runs once with the builder as its receiver. Exceptions from the action propagate to the caller. As an inline action, it supports non-local returns.
val message = buildString {
append("Hello, ")
append("world!")
}Return
an independent snapshot of the content after the action completes normally.
Parameters
action that writes the result into the builder.
Builds an immutable String with a builder sized for the expected content.
Capacity is an allocation hint, not a length limit: the builder starts empty and grows as needed. The action runs once with the builder as its receiver; its exceptions propagate to the caller. The inline action supports non-local returns.
Return
an independent snapshot of the content after the action completes normally.
Parameters
initial buffer size in UTF-16 code units.
action that writes the result into the builder.
Throws
if capacity is negative, before the action runs.