开发者

Return position of an item in ArrayList

I know that I can iterate the list and prove every element of the list. But I was wondering if there is better solut开发者_StackOverflowion to get the position of an item in an ArrayList?


The List API offers you the indexOf() method for that so that you don't need to manually iterate.

int index = list.indexOf(item);

See also:

  • Java tutorials - Collections - List interface
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜