- public StringBuilder append(任意类型) //添加数据,并返回对象本身
- public StringBuilder reverse() //返回相反的字符序列
代码演示:
package test;
public class Main {
public static void main(String[] args) {
StringBuilder s = new StringBuilder();
StringBuilder s1 = s.append("WTY");//添加对象,并返回对象本身
System.out.println("s:" + s);
System.out.println("s1:" + s1);
System.out.println(s == s1); // s和s1其实是同一个对象
System.out.println("--------");
s1 = s.append(19);
System.out.println("s:" + s);
System.out.println("s1:" + s1);
System.out.println(s == s1);
System.out.println("--------");
StringBuilder s2 = new StringBuilder();
s2.append("WTY").append(19);//链式编程法
System.out.println("s2:" + s2);
System.out.println("--------");
//反转
s2.reverse();
System.out.println("s2:" + s2);
}
}
运行结果: