Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The string concatenation operator (+) is a convenient way to combine a few strings into one. It is fine for generating a single line of output or for constructing the string representation of a small, fixed-size object, but it does not scale. 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 (Item 15). When two strings are concatenated, the contents of both are copied.
For example, consider the following method that constructs a string representation of a billing statement by repeatedly concatenating a line for each item: