1.string 和stringbuilder的字符串拼接原理

String 和 StringBuilder_string

2.string 转化为stringBuilder类

         String string1="hello";
         StringBuilder sl=new StringBuilder(string1);

3.StringBuiler 转化为String:StringBuiler 和String 的区别是StringBuiler提高效率

         String string1="hello";
         StringBuilder sl=new StringBuilder(string1);
         sl.append("word");
         System.out.println(" StringBuilder返回的是字符串对象本身"+sl);//helloword
         String restring=sl.toString();

         System.out.println(" StringBuilder对象变为string字符串后输出的内容为:"+restring);//helloword

4.无参构造方法

        StringBuilder st=new StringBuilder();
        System.out.print("st"+st); //什么都没输出

5.有参构造:

        StringBuilder sbl2=new StringBuilder("初始值");
        System.out.print("sbl2"+sbl2);//sbl2初始值

 

 

 6.常用方法appled

 private static void stbapped() {
        StringBuilder sbl2=new StringBuilder();
        StringBuilder sbl3=sbl2.append("abc");
        System.out.print(sbl2);//abc
        System.out.print(sbl3);//abc
        System.out.print(sbl2==sbl3);//true
        //返回当前对象自身,使用的时候无需接收返回值
        StringBuilder sbl4=new StringBuilder();
        sbl4.append(11);
        sbl4.append("测试数据");
        System.out.print("sbl4的值是"+sbl4);//sbl4的值是11测试数据
    }