Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1><code>+</code> operator</h1> <pre><code>String s = s1 + s2 </code></pre> <p>Behind the scenes this is translated to:</p> <pre><code>String s = new StringBuilder(s1).append(s2).toString(); </code></pre> <p>Imagine how much extra work it adds if you have <code>s1 + s2</code> here:</p> <pre><code>stringBuilder.append(s1 + s2) </code></pre> <p>instead of:</p> <pre><code>stringBuilder.append(s1).append(s2) </code></pre> <h2>Multiple strings with <code>+</code></h2> <p>Worth to note that:</p> <pre><code>String s = s1 + s2 + s3 + ... +sN </code></pre> <p>is translated to:</p> <pre><code>String s = new StringBuilder(s1).append(s2).append(s3)...apend(sN).toString(); </code></pre> <h1><code>concat()</code></h1> <pre><code>String s = s1.concat(s2); </code></pre> <p><code>String</code> creates <code>char[]</code> array that can fit both <code>s1</code> and <code>s2</code>. Copies <code>s1</code> and <code>s2</code> contents to this new array. Actually requires less work then <code>+</code> operator.</p> <h1><code>StringBuilder.append()</code></h1> <p>Maintains an internal <code>char[]</code> array that grows when needed. No extra <code>char[]</code> is created if the internal one is sufficiently big.</p> <pre><code>stringBuilder.append(s1.concat(s2)) </code></pre> <p>is also performing poorly because <code>s1.concat(s2)</code> creates an extra <code>char[]</code> array and copies <code>s1</code> and <code>s2</code> to it just to copy that new array contents to internal <code>StringBuilder</code> <code>char[]</code>.</p> <p>That being said you should use <code>append()</code> all the time and append raw strings (your first code snippet is correct).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload