I have an array like so:
String[] articles = {"a", "and", "the"};
And I want to know how to get the array index from a certain term. Is there a method along the lines of articles.getIndex("the"); and it will return an int (in this case, 2)?
Sign up to request clarification or add additional context in comments.
Comments
0
You can also write method for that
public int indexByValue(String data, String[] array) {
int index = -1;
for (int i = 0; i < array.length; i++)
if (array[i].equals(data)) index = i;
return index;
}