3 ms·
The advantage of making the string type immutable is that you can do what's known as "string interning": if the same string shows up multiple times in your prog
by amarkov 9y ago
The advantage of making the string type immutable is that you can do what's known as "string interning": if the same string shows up multiple times in your program, only one copy has to be kept in memory. This is particularly useful for compile-time constant strings.
C and C++ actually do a similar thing with their string literals, which are immutable even though normal strings aren't.