All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S3027.html Maven / Gradle / Ivy

There is a newer version: 8.9.0.37768
Show newest version

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