gpt4 book ai didi

java - 获取List的Arraylist中与Arraylist匹配的数据

转载 作者:行者123 更新时间:2023-12-02 02:00:12 26 4
gpt4 key购买 nike

我有以下ArrayList:

public static List c = new ArrayList();
c = [1,2,3];

我在 ArrayList 中有以下列表:

public static ArrayList<List<String>> Contact = new ArrayList<List<String>>();
Contact = (["One",1], ["Two", 2], ["Three",3], ["Four", 4])

如何比较列表以获取具有以下值的新列表:

[“一”,“二”,“三”]???

基本上:我想检查整数,看看它是否存在于列表中项目的第二个值中,如果存在,则添加第一个项目,到新列表。

最佳答案

与其创建 ArralyList>,不如使用 HashMap

将数据作为

c = [1,2,3];

Map<Int, String> data = new HashMap();
data.put(1, "One");
data.put(2, "Two");
data.put(3, "Three");

ArrayList<String> output = new ArrayList()
for(int i=0 i<c.length; i++) {
output.add(data.get(c[i]));
}

现在输出将包含数据 ["One", "Two", "Three"]

关于java - 获取List的Arraylist中与Arraylist匹配的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51692786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com