0

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.

1
  • See "For Object arrays" in Tunaki's answer on the dupe. Commented Jul 29, 2019 at 23:28

1 Answer 1

0

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;
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.