I'm trying to get specific indexed value by key using arraylist.get(2); but failed, also is throws an exception.
"IndexOutOfBoundsException: Invalid index 2, size is 1"
Where as my arraylist is of size 3 (0-2).
Here's my method code below:
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    //add keys to arraylist
    String key=dataSnapshot.getKey();
    arraylist.add(key);
    //it displays found indexes as 0, 1, 2
    int index= arraylist.indexOf(key);
    Log.i("indexs", String.valueOf(index));
    //it displays exception, but when I replace "2" with "0" then, 
    //it prints one value four times which lie on index "1"
    String specificIndexValue = arraylist.get(2);
    Log.i("IndexValues", specificIndexValue);
}
 
    