Java基础-StringBuilder类型和StringBuffer类型与String类型相互转换

将String类转换成StringBuilder类(同String类转换成StringBuffer类):

String s = “某某某”;
StringBuilder sb = new StringBuilder(s);

将StringBuilder转换成String类:

StringBuilder sb = new StringBuilder();
String s = “”+sb;

将StringBuffer类型转换成String类:

可以直接调用toString()方法:
StringBuffer sb = new StringBuffer;
String s = sb.toString;

你可能感兴趣的:(大厂之路,#,Java基础,StringBuffer,StringBuilder,String类型转换)