public class Demo4_StringBuffer {
/**
* @param args
*/
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("woaiheima");
System.out.println(sb); //通过构造方法将String转换为StringBuffer
StringBuffer sb1 = new StringBuffer();
sb1.append("woaiheima");
System.out.println(sb1); //通过append方法将String转换为StringBuffer
String sb2 = new String(sb); //通过构造方法将StringBuffer转换为String
System.out.println(sb2);
//常用方法
String sb3 = sb.toString();
System.out.println(sb3); //通过调用toStringBuffer方法将String转换为String
String sb4 = sb.substring(0,sb.length()); //通过调用substringBuffer截取方法将String转换为String
System.out.println(sb4);
}
} |
|