I have an array
String[] values = new String[] {"AB","BC","CD","AE"};
I wanna find the index of the String BC
. I know we can use indexOf
for integers but wasn't able to find anything simple for string.
I have an array
String[] values = new String[] {"AB","BC","CD","AE"};
I wanna find the index of the String BC
. I know we can use indexOf
for integers but wasn't able to find anything simple for string.
You can perform a linear search, like:
int index = -1;
for (int i = 0; i < values.length; i++) {
if (values[i].equals("BC") {
index = i;
}
}