0

Mutable string

What does it mean when string is "mutable"?

19th Feb 2019, 9:41 AM
Adrian Grill
Adrian Grill - avatar
2 Respostas
+ 3
It means you can change it. If your string was immutable and you wanted to change the first character, you would have to create a new string and copy the contents over (or it's done automatically for you, depends on the language). But since the string is mutable you can just change the existing string. This may have unintended consequences, if different parts of your code use the same string. You might change it in places where you didn't mean to.
19th Feb 2019, 9:52 AM
Schindlabua
Schindlabua - avatar
+ 1
Thank you so much! 😊
19th Feb 2019, 9:53 AM
Adrian Grill
Adrian Grill - avatar