mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
33 lines
1.1 KiB
HTML
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<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<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> |