//String --> StringBuffer
StringBuffer sb = new StringBuffer();
sb.append("Java");
System.out.println(sb);
//StringBuffer --> String
//方式1
StringBuffer sb = new StringBuffer("Hello");
//通过 toString()
System.out.println(sb.toString());
//方式2
//通过String类的构造方法
StringBuffer sb = new StringBuffer("Hello");
String str = new String(sb);
System.out.println(str);
//方式3
//3: 通过String类的方法 public static String valueOf(Object obj)
StringBuffer sb = new StringBuffer("Hello");
String result = String.valueOf(sb);
System.out.println(result);
|
|