Calling String.indexOf() with a single character string is inefficientJAVA-P1004
This code passes a single character string, or an empty string to String.indexOf(). Doing so is useless at best, and is also more inefficient than passing a character directly.
Bad Practice
// Use a character or int value instead.
"abc.cat".indexOf(".");
// This will always return index 0.
"abc.cat".indexOf("");
If there is an empty string in the first argument to indexOf, it may indicate that a typo was committed.
Recommended
It is more efficient to use the integer implementations of indexOf():
myString.indexOf('.')
References
- Oracle Java 11 JavaDocs -
java.lang.String