9 ms·
Strings are immutable. Variables can be reassigned. Those are two very different things. Strings being immutable means that you can can pass around references
by jhomedall 8y ago
Strings are immutable. Variables can be reassigned. Those are two very different things.
Strings being immutable means that you can can pass around references to them, safe in the knowledge that they can't be modified.
For example:
void example() {
String s = "hello";
someOtherMethod(s);
// `s` is guaranteed to still be "hello" here.
}
Or, a live example using repl.it: https://repl.it/repls/BothTrivialQuadrant https://repl.it/repls/BothTrivialQuadrant