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
精彩评论