[Solved] Java Strings are immutable? [duplicate]


The object itself didn’t change.

What you have done is the following

name <- String("Paul")
name <- String("Henry")

String(“Paul”) has been not been changed.

Try the following:

String a = "test";
String b = a;
a = "test2";

System.out.println(b);

solved Java Strings are immutable? [duplicate]