两者在方法及操作上没有什么区别,唯一区别是,StringBuffer是线程安全的,StringBuilder非线程安全,
如果在不用考虑到线程安全问题就可以使用StringBuiler,这样可以提高拼接速度。
StringBuffer 中的代码:
public synchronized StringBuffer append(String str) {
super.append(str);
return this;
}
StringBuilder中的代码:
public StringBuilder append(String str) {
super.append(str);
return this;
}