Differences between StringBuffer and StringBuilder
This question already has an answer here:
As stated in their javadoc (http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html and http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html), StringBuffer and StringBuilder provider the same set of operations. The only difference between them is that operations in StringBuffer are synchronized, whereas operations in StringBuilder are not.
Because operations in StringBuffer are synchronized, StringBuffer are thread safe, which means that multiple threads can safely operate on the same StringBuffer. In contrast, operations in StringBuilder are not synchronized. If multiple threads need to operate on the same StringBuffer, you need to synchronize these threads manually (or, use StringBuffer).
Synchronization requires the threads to acquire locks. Because synchronized methods perform this extra operation, it is slower than non-synchronized methods.
In summary, if you just want to construct a String, and it does not involve multiple threads, then it is better to use StringBuilder than StringBuffer.
链接地址: http://www.djcxy.com/p/72348.html