org.sonar.l10n.java.rules.squid.S3027.html Maven / Gradle / Ivy
An indexOf
or lastIndexOf
call with a single letter String
can be made more performant by switching to a call with a char
argument.
Noncompliant Code Example
String myStr = "Hello World";
// ...
int pos = myStr.indexOf("W"); // Noncompliant
// ...
int otherPos = myStr.lastIndexOf("r"); // Noncompliant
// ...
Compliant Solution
String myStr = "Hello World";
// ...
int pos = myStr.indexOf('W');
// ...
int otherPos = myStr.lastIndexOf('r');
// ...
© 2015 - 2025 Weber Informatics LLC | Privacy Policy