我读了很多关于字符串对象是不可变的,只有字符串缓冲区是可变的。但是当我尝试这个程序时。我很困惑。那么这个程序中发生了什么。
class Stringss {
public static void main(String[] args) {
String s="hello";
String ss=new String("xyz");
System.out.println(ss);
System.out.println(s);
s="do";
ss=new String("hello");
System.out.println(s);
System.out.println(ss);
}
}
输出是
xyz
hello
do
hello