3 ms·
This is true, javac only replaces individual concatentations with use of a StringBuilder, so foo + bar + baz + "!" is fast, but performing a concatenation in a
by jmgao 12y ago
This is true, javac only replaces individual concatentations with use of a StringBuilder, so foo + bar + baz + "!" is fast, but performing a concatenation in a loop does multiple copies for each iteration. It (or the JIT) could conceivably do escape analysis to optimize simple cases like this, but it doesn't.
builder: http://hastebin.com/qadusoriqa.cs http://hastebin.com/qadusoriqa.cs
concat: http://hastebin.com/nasukuxemi.cs http://hastebin.com/nasukuxemi.cs