setLength

Common
JS
Native
1.3
fun setLength(newLength: Int)

Sets the length of this string builder to the specified newLength.

If the newLength is less than the current length, it is changed to the specified newLength. Otherwise, null characters '\u0000' are appended to this string builder until its length is less than the newLength.

Note that in Kotlin/JS set operator function has non-constant execution time complexity. Therefore, increasing length of this string builder and then updating each character by index may slow down your program.

Exceptions

IndexOutOfBoundsException - or IllegalArgumentException if newLength is less than zero.