字符串 String 之 StringBuffer

 

 @Test
    public void f() {
        String s1 = "a";
        String tmp = s1;
        s1 += "b";
        System. out. println(tmp); //a
        System. out. println(s1) ; //ab

    }

    @Test
    public void f1(){
            StringBuffer sb1 = new StringBuffer("a");
            StringBuffer tmp = sb1;
            sb1. append("b");
            sb1. append("c");
            sb1. append("d");
            sb1. append("e");
            System. out . println(tmp); //abcde
            System . out . println(sb1);//abcde
    }

   StringBuffer 的兄弟

 

posted @ 2023-07-13 16:54  OYそ  阅读(3)  评论(0编辑  收藏  举报