• public StringBuilder append(任意类型) //添加数据,并返回对象本身
    • public StringBuilder reverse() //返回相反的字符序列

    代码演示:

    1. package test;
    2. public class Main {
    3. public static void main(String[] args) {
    4. StringBuilder s = new StringBuilder();
    5. StringBuilder s1 = s.append("WTY");//添加对象,并返回对象本身
    6. System.out.println("s:" + s);
    7. System.out.println("s1:" + s1);
    8. System.out.println(s == s1); // s和s1其实是同一个对象
    9. System.out.println("--------");
    10. s1 = s.append(19);
    11. System.out.println("s:" + s);
    12. System.out.println("s1:" + s1);
    13. System.out.println(s == s1);
    14. System.out.println("--------");
    15. StringBuilder s2 = new StringBuilder();
    16. s2.append("WTY").append(19);//链式编程法
    17. System.out.println("s2:" + s2);
    18. System.out.println("--------");
    19. //反转
    20. s2.reverse();
    21. System.out.println("s2:" + s2);
    22. }
    23. }

    运行结果:
    image.png