Files
openide/java/java-impl/resources/inspectionDescriptions/StringConcatenationInLoops.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

33 lines
1.1 KiB
HTML

<html>
<body>
Reports String concatenation in loops.
<p>
As every String concatenation copies the whole
string, usually it is preferable to replace it with explicit calls to <code>StringBuilder.append()</code> or
<code>StringBuffer.append()</code>.
</p>
<p><b>Example:</b></p>
<pre><code>
String str = "";
for(int i=0; i&lt;10; i++) {
str += i;
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
String str = "";
StringBuilder strBuilder = new StringBuilder(str);
for(int i = 0; i&lt;10; i++) {
strBuilder.append(i);
}
str = strBuilder.toString();
</code></pre>
<!-- tooltip end -->
<p>
Sometimes, the quick-fixes allow you to convert a <code>String</code> variable to a <code>StringBuilder</code> or
introduce a new <code>StringBuilder</code>. Be careful if the original code specially handles the <code>null</code> value, as the
replacement may change semantics. If <code>null</code> is possible, null-safe fixes that generate
necessary null-checks are suggested. Also, it's not guaranteed that the automatic replacement will always be more performant.
</p>
</body>
</html>