public static void main(String[] args){
String str1 = "Hello";
System.out.println(str1);
tell(str1);
System.out.println(str1);
}
public static void tell(String str2){
str2 = "Hi";
}
output: Hello
Hello
Is this example suitable for string immutable? I think reference str2 might changed str1 String value caused both of them reference to the same address. If the String class is mutable, the output might be Hello Hi, and because of the immutable characteristic, the final result is Hello Hello.
Is the reason right for this example?
http://www.explain-java.com/is-string-mutable-in-java-why-wrapper-classes-immutable-in-java/
This web page has the same example as me. Am I really wrong?
If I am right, plz vote me up to let more people know the truth of String immutable.