我有类(class)列表A:
public class lista {
int i;
String name;
public lista(int i, String name)
{
this.i = i;
this.name = name;
}
}
我从这个类中创建了ArrayList。
public static ArrayList<lista> friends;
添加一些日期: 14 - 亚当 2 - 约翰 35 - 阿诺德 74 - x 54 - x
我想要获取 IndexOf 74 并将名称从 x 更改为 Catrina。
怎么做?
friends.get(friends.indexOf(??)) = "catarina";
最佳答案
看来您最好使用Map
,因为它们能够更好地处理您在这里拥有的键值对。
Map<Integer, String> friends = new HashMap<Integer, String>();
friends.put(14, "Adam");
friends.get(14); //Adam
friends.put(14, "John");
friends.get(14); //Now John
关于java - 获取类的数组列表的索引。 java ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15221146/