TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - Java Coding Standard
Search

Rule:  StringandStringBuffer9Checked automatically with code checker

Synopsis:String.indexOf(char) is faster than String.indexOf(String)
Language:Java
Severity Level:4
Category:StringandStringBuffer


Description:
Use String.indexOf(char) when checking for the index of a single character; it executes faster.
public class Foo {
 void bar() {
  String s = "hello world";
  // avoid this
  if (s.indexOf("d") {}
  // instead do this
  if (s.indexOf('d') {}
 }
}