一、String轉(zhuǎn)化為StringBuffer類
方法一:使用StringBuffer類的構(gòu)造方法疆前,public StringBuffer(String str)
public class Person { public static void main(String[] args) { String str ="hello world"; StringBuffer buf = new StringBuffer(); buf.append(str); System.out.println(buf); } }
方法二:利用StringBuffer類的append()方法
public class Person { public static void main(String[] args) { String str ="hello world"; StringBuffer buf = new StringBuffer(str); System.out.println(buf); } }
二肚逸、StringBuffer轉(zhuǎn)化為String
利用StringBuffer類的toString()方法完成
public class Person { public static void main(String[] args) { StringBuffer buf=new StringBuffer(); buf.append("hello world"); String str = buf.toString(); System.out.println(str); } }