java - 获取类的数组列表的索引。 java

标签 java arrays class arraylist

我有类(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/

相关文章:

java - 捆绑的 Java OS X 应用程序默认为 MacRoman 编码

java - Google Places API,添加地点始终返回 INVALID_REQUEST

javascript - 通过包含在另一个数组中的对象属性对 Javascript 数组进行排序

java.lang.IllegalStateException : Expected BEGIN_OBJECT but was STRING at line 1 column 62 错误

java - 不使用序列的数字主键;如何获取下一个值?

java - 我正在制作一个24小时时钟

javascript - 导出数组中元素的所有可能组合

Php:单例VS全静态类?什么时候用什么?

java - 类方法未执行正确的计算

ios - 如何在类方法中返回 self ?