public class StringTest{ String s="asdf"; String s1=s; //s1 and s have the same object handle s1=s1+"world"; System.out.println(s); } the result is: asdf; public class StringBuffer{ StringBuffer sb=new StringBuffer("nihao"); StringBuffer sb1=sb; sb.append("world"); System.out.println(sb1); } the result is:nihaoworld
String s="asdf";
String s1=s; //s1 and s have the same object handle
s1=s1+"world";
System.out.println(s);
}
the result is: asdf;
public class StringBuffer{
StringBuffer sb=new StringBuffer("nihao");
StringBuffer sb1=sb;
sb.append("world");
System.out.println(sb1);
}
the result is:nihaoworld