title: Does Java Compiler include String Constant Folding?
body: <p>I found out that <a href="https://stackoverflow.com/questions/2264178/what-is-constant-folding-in-java-compiler">Java supports constant folding of primitive types</a>, but what about <code>String</code>s?</p>
  
  <p><strong>Example</strong></p>
  
  <p>If I create the following source code</p>
  
  <pre><code>out.write(""
          + "&lt;markup&gt;"
          + "&lt;nested&gt;"
          + "Easier to read if it is split into multiple lines"
          + "&lt;/nested&gt;"
          + "&lt;/markup&gt;"
          + "");
  </code></pre>
  
  <p>What goes into the compiled code? </p>
  
  <p>Combined Version? <code>out.write("&lt;markup&gt;&lt;nested&gt;Easier to read if it is split into multiple lines&lt;/nested&gt;&lt;/markup&gt;");</code></p>
  
  <p>Or the less efficient run-time concatenation version? <code>out.write(new StringBuilder("").append("&lt;markup&gt;").append("&lt;nested&gt;").append("Easier to read if it is split into multiple lines").append("&lt;/nested&gt;").append("&lt;/markup&gt;").append(""));</code></p>