How many string additions do you need for a StringBuilder to be more efficient?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4191079/stringbuilder-vs-string-concat">Stringbuilder vs String.Concat</a>  </p>
</blockquote>



<p>As I understand it, String are immutable, so if you do <code>"one " + "two"</code>, rather than reusing the memory of these two strings, a new string is created with value "one two". This becomes a problem if you do something like:</p>

<pre><code>String output = "";
for (int i = 0; i &lt; 20; i++){
    output = output + ii.toString();
}
</code></pre>

<p>Because 19 (or 39?) strings are created and discarded to produce the final desired output.</p>

<p>String builders are mutable, so you can add strings together efficiently, and then convert them into a string when you are done.</p>

<p>I assume there is some overhead in creating string builders, and also the clever compilers used today optimize away lots of string addition problems. So my question is: how many strings do I need to add together before it becomes more efficient to use a StringBuilder instead? Or are my assumptions incorrect?</p>
