131 if (dot != -1) {
132 version = version.substring(0, dot);
133 } else {
134 final int separator = version.indexOf("-");135 if (separator != -1) {
136 version = version.substring(0, separator);
137 }
127 if (version.startsWith("1.")) {
128 version = version.substring(2, 3);
129 } else {
130 final int dot = version.indexOf(".");131 if (dot != -1) {
132 version = version.substring(0, dot);
133 } else {
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.
// 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.
It is more efficient to use the integer implementations of indexOf()
:
myString.indexOf('.')
java.lang.String