The following code doesn't work in Kotlin:
var s: String = "hello"
s[1]='a'
Does Kotlin have a mutable string type or do I have to use an Array<Char>
if I want to be able to edit?
No, it doesn't.
You can use a StringBuilder to manipulate it:
val sb = StringBuilder("hello")
sb[1] = 'a'
println(sb.toString())
hallo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With