Better way to find index of item in ArrayList?

后端 未结 8 2042
不知归路
不知归路 2020-12-04 11:50

For an Android app, I have the following functionality

private ArrayList _categories; // eg [\"horses\",\"camels\"[,etc]]

private int getCateg         


        
8条回答
  •  半阙折子戏
    2020-12-04 12:28

    Java API specifies two methods you could use: indexOf(Object obj) and lastIndexOf(Object obj). The first one returns the index of the element if found, -1 otherwise. The second one returns the last index, that would be like searching the list backwards.

提交回复
热议问题