4 Answers
4

Either way you'll be creating a lot of unnecessary temporary Strings. Strongly recommend using StringBuilder instead. The compiler will actually use temporary StringBuilder instances when you use the + operator, but it doesn't have the broader vision of what you're trying to achieve and is limited in terms of how much it can optimize the StringBuilder use, so you'll almost always do a better job making it explicit.

If you are focusing on performance (it is a commonly used or key area of code) you would also preallocate the size of the buffer (initial capacity in the constructor) used for the string so the buffer doesn't have to be resized.
–
Jim RushDec 7 '09 at 12:07

Yes, you should avoid the obvious
beginner mistakes of string
concatenation, the stuff every
programmer learns their first year on
the job. But after that, you should be
more worried about the maintainability
and readability of your code than its
performance. And that is perhaps the
most tragic thing about letting
yourself get sucked into
micro-optimization theater -- it
distracts you from your real goal:
writing better code.

Cool article. I make decision by folow rule: 1. more readable - more good. 2. if more than 8 contactions - always use StringBuilder. More pretty for me. And this is a sing "Hey! I'm building string here".
–
St.ShadowDec 7 '09 at 12:17

So...? Did you read/understand the article?
–
JeromeDec 7 '09 at 12:47

Yes, No sign of Java at the blog entry (just at the comments). No Java code, looks like C# or similar. Even if the code would be Java code and he tested it with Java, the benchmarks would be nonsense, as no warmup has been made. The article is just not suitable for Java.
–
HardcodedDec 7 '09 at 12:59