Item 51: Beware the performance of string concatenation

1.  Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic in n. It is an unfortunate consequence of the fact that strings are immutable.

 

2.  To achieve acceptable performance, use a StringBuilder in place of a String to store the string under construction. The StringBuilder class, added in release 1.5, is an unsynchronized replacement for StringBuffer, which is less efficient in single thread environment.

 

你可能感兴趣的:(StringBuilder)