看注释
public class AppendRevertString {
public static void main(String[] args) {
StringBuffer s2=null;
StringBuffer s1=new StringBuffer("12345");
System.out.println(s1);
System.out.println("倒序后得到的结果是:");
s2=s1.reverse(); //s1倒序之后是“54321”,s2指向了s1的地址,也就是说s2,s1代表的都是“54321”
s1.append(s2); //s1是“54321”,s2也是“54321”,连接在一起就是5432154321
System.out.println(s1); //输出5432154321
}
}
|