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') {} } } |