mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
31 lines
906 B
HTML
31 lines
906 B
HTML
<html>
|
|
<body>
|
|
Reports variables declared as <code>java.lang.String</code> that are
|
|
repeatedly appended to. Such variables could be declared more efficiently as <code>java.lang.StringBuffer</code>
|
|
or <code>java.lang.StringBuilder</code>.
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
String s = "";
|
|
for (int i = 0; i < names.length; i++) {
|
|
String name = names[i] + (i == names.length - 1 ? "" : " ");
|
|
s = s + name;
|
|
}
|
|
</code></pre>
|
|
<p>Such a loop can be replaced with:</p>
|
|
<pre><code>
|
|
StringBuilder s = new StringBuilder();
|
|
for (int i = 0; i < names.length; i++) {
|
|
String name = names[i] + (i == names.length - 1 ? "" : " ");
|
|
s.append(name);
|
|
}
|
|
</code></pre>
|
|
<p>Or even with:</p>
|
|
<pre><code>
|
|
String s = String.join(" ", names);
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Use the option to make this inspection only report when the variable is appended to in a loop.
|
|
</p>
|
|
</body>
|
|
</html> |