这两天看公司以前的代码写的用很多字符串相加没有用StringBuffer和StringBuilder,为了重构方便写了一个工具类:
public class StringBufferUtil {
public static String convertByStringBuilder(Object... obj) {
StringBuilder sb = new StringBuilder("");
for (Object o : obj) {
if(o == null){
sb.append("");
}else{
sb.append(o);
}
}
return sb.toString();
}
public static String convertByStringBuffer(Object... obj) {
StringBuffer sb = new StringBuffer("");
for (Object o : obj) {
if(o == null){
sb.append("");
}else{
sb.append(o);
}
}
return sb.toString();
}
}