本帖最后由 ksh 于 2015-9-24 16:19 编辑
求分析
--------------------------------------------------------
public class StringStringBuffer {
public static void main(String[] args) {
String s1 = "hello";
String s2 = "world";
System.out.println(s1+"---"+s2);//hello---world
change(s1,s2);
System.out.println(s1+"---"+s2);//hello---world
System.out.println("-------");
StringBuffer sb1 = new StringBuffer("hello");
StringBuffer sb2 = new StringBuffer("world");
System.out.println(sb1+"---"+sb2);//hello---world
change(sb1,sb2);
System.out.println(sb1+"---"+sb2);//hello---worldworld
}
private static void change(String s1, String s2) {
s1=s2;
System.out.println(s1+"---"+s2);//world---world
s2=s1+s2;
System.out.println(s1+"---"+s2);//world---worldworld
}
private static void change(StringBuffer sb1, StringBuffer sb2) {
sb1= sb2;
System.out.println(sb1+"---"+sb2);//world---world
sb2.append(sb1);
System.out.println(sb1+"---"+sb2);//worldworld---worldworld
}
}---------------------------------------------
hello---world
world---world
world---worldworld
hello---world
-------
hello---world
world---world
worldworld---worldworld
hello---worldworld
---------------------------------------------
表示看的不太懂
|
|