buildString with initial capacity for the StringBuilder instance

this method helps save computation time when the developer knows or have a good
educated guess about the size of the generated string and have to use control
structures while filling the string builder

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
This commit is contained in:
Laszlo Hornyak
2016-04-27 07:34:38 +02:00
committed by Ilya Gorbunov
parent 4e18e91463
commit 6fda0816f3
2 changed files with 13 additions and 0 deletions
@@ -5,6 +5,13 @@ import kotlin.test.*
import org.junit.Test as test
class StringBuilderJVMTest() {
@test fun stringBuildWithInitialCapacity() {
val s = buildString(123) {
assertEquals(123, capacity())
}
}
@test fun getAndSetChar() {
val sb = StringBuilder("abc")
sb[1] = 'z'