0

For example I have JSONArray of strings:

["hello", "dear", "community"]

and I want to get index of "dear". How would I do that?

I am iterating over an array and want to check is array element in my JSONArray and get its index.

1 Answers1

5

There is no direct way of getting that. Unless you loop through the objects and find the index for the matching string.

for(int i=0;i<arr.length();i++) {
            if("dear".equals(arr.get(i))) {
                return i;
            }
        }
Hirak
  • 3,601
  • 1
  • 22
  • 33