Sun Java System Web Server 7.0 Update 7 Performance Tuning, Sizing, and Scaling Guide

Use StringBuffer to Concatenate Strings

To improve performance, instead of using string concatenation, use StringBuffer.append(). String objects are immutable; they never change after creation. For example, consider the following code:

tring str = "testing";
str = str + "abc";

The compiler translates this code as:

String str = "testing";
StringBuffer tmp = new StringBuffer(str);
tmp.append("abc");
str = tmp.toString();

Therefore, copying is inherently expensive and overusing it can reduce performance significantly.