编程语言
首页 > 编程语言> > java中StringBuffer和StringBuilder

java中StringBuffer和StringBuilder

作者:互联网

StringBuffer

String vs StringBuffer 

public class String_Buffer {
    public static void main(String[] args) {

        //String ---> String Buffer   String转为StringBuffer
        String fun = "hello";
        //方式一 使用构造器
        StringBuilder stringBuilder = new StringBuilder(fun);
        //方式二 使用append
        StringBuilder stringBuilder1 = new StringBuilder();
        stringBuilder1.append(fun);


        //String Buffer ---> String   StringBuffer转为String
        StringBuilder pfc = new StringBuilder("平凡晨");
        //方式一 toString()方法
        String string = pfc.toString();
        //方式二 使用构造器
        String s = new String(pfc);
        System.out.println(s);
    }
}

StringBuilder

String、StringBuffer 和 StringBuilder 的比较

 

 

String、StringBuffer 和 StringBuilder 的选择

 

标签:pfc,java,String,Buffer,StringBuffer,StringBuilder,new
来源: https://www.cnblogs.com/ityc/p/15987906.html