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.
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.
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;
}
}