开发者

Return position of an item in ArrayList

开发者 https://www.devze.com 2023-03-29 06:15 出处:网络
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

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

精彩评论

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