Performance wise String concatenation using '+' is costlier because it has to make a whole new copy of String since Strings are immutable in java. This plays particular role if concatenation is very frequent, eg: inside a loop. Following is what my IDEA suggests when I attempt to do such a thing:
General Rules:
- Within a single string assignment, using String concatenation is fine.
- If you're looping to build up a large block of character data, go for StringBuffer.
- Using += on a String is always going to be less efficient than using a StringBuffer, so it should ring warning bells - but in certain cases the optimisation gained will be negligible compared with the readability issues, so use your common sense.
Here is a nice Jon Skeet blog around this topic.
