Java StringBuilder 和 String 相互转换
作者:互联网
public class test {
public static void main(String[] args) {
// 创建对象
StringBuffer sb = new StringBuffer();
sb.append("dzm");
// 将 StringBuffer 转换为 String
String str = sb.toString();
// String 转换为 StringBuffer
StringBuffer sb2 = new StringBuffer(str);
// 输出
System.out.println(str);
System.out.println(sb2);
}
}
标签:sb2,Java,String,StringBuilder,str,StringBuffer,sb,out 来源: https://blog.csdn.net/zz00008888/article/details/117924254