String和StringBuffer的相互转化

String 字符串
StringBuffer 字符串缓冲区

String 到 StringBuffer
1.new StringBuffer(String str);
2.new StringBuffer().append(String str);
也可以靠一些置换方法如replac();
StringBuffer到string
1.new StringBuffer().toString();
2.new StringBuffer().substring();通过截取

猜你喜欢

转载自blog.csdn.net/weixin_43791033/article/details/85287415