开发者

get Item Index of arrayList knowing its Name

开发者 https://www.devze.com 2023-03-28 04:16 出处:网络
is there a function that take array list item and bring back item index ? for开发者_StackOverflow社区 ex:

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> ?

0

精彩评论

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

关注公众号