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:
committed by
Ilya Gorbunov
parent
4e18e91463
commit
6fda0816f3
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user