get Item Index of arrayList knowing its Name
is there a function that take array list item and bring back item index ?
for开发者_StackOverflow社区 ex:
int indexItem = ArrayList.getItemIndexByName(itemName);
I think that you are looking for IndexOf.
int indexItem = myArray.IndexOf(itemName);
You can use it like this.
String itemName = "Hello";
ArrayList myArray = new ArrayList();
myArray.Add( "Hello" );
myArray.Add( "World" );
// Get index of "Hello"
int indexItem = myArray.IndexOf(itemName);
There is no single method that will give you this, but you could first search for your item by name, then use ArrayList.IndexOf.
Tried storing your items in a Dictionary<string, MyItemType>
?
精彩评论