Files
openide/java/java-impl/resources/inspectionDescriptions/SingleCharacterStartsWith.html
2025-02-05 04:43:28 +00:00

30 lines
1.0 KiB
HTML

<html>
<body>
Reports calls to <code>String.startsWith()</code> and
<code>String.endsWith()</code> where single character string literals are passed as an argument.
<p>
A quick-fix is suggested to replace such calls with more efficiently implemented <code>String.charAt()</code>.
</p>
<p>
However, the performance gain of such change is minimal and the code becomes less readable because of the extra non-zero length check,
so it is recommended to apply the quick-fix only inside tight loops.
</p>
<p>
This inspection is intended for Java ME and other highly resource constrained environments.
Applying the results of this inspection without consideration might have negative effects on code clarity and design.
</p>
<p><b>Example:</b></p>
<pre><code>
boolean startsWithX(String s) {
return s.startsWith("x");
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
boolean startsWithX(String s) {
return !s.isEmpty() && s.charAt(0) == 'x';
}
</code></pre>
<!-- tooltip end -->
</body>
</html>