A String cannot be changed
Once a String object exists, its characters never change. Every method that looks like it edits a string actually returns a new string.
public class Immutable {
public static void main(String[] args) {
String s = "hello";
s.toUpperCase(); // result thrown away
System.out.println(s); // hello
s = s.toUpperCase(); // now s points at the new object
System.out.println(s); // HELLO
String t = "abc";
t.concat("def");
System.out.println(t); // abc, not abcdef
}
}