We all know that using StringBuffer to perform String concatenations is far more efficient than conctenating strings using the '+' operator. Since JDK 1.5 a new class called StringBuilder has been added. StringBuilder is just like StringBuffer, except that it's methods are not synchronized. You should use StringBuilder to improve your performance if you do not need thread safety.
Shown below is an example that concatanates 10000 strings using the '+' operator, StringBuffer, and StringBuilder, and prints the operation time in nanoseconds. The ability to get time in nanoseconds is another feature that was added in JDK 1.5.
Notes: This text was originally posted on my earlier blog at http://www.adaptivelearningonline.net