gpt4 book ai didi

java - 找不到适合 put(int, ArrayList) 的方法

转载 作者:行者123 更新时间:2023-11-29 07:24:50 26 4
gpt4 key购买 nike

我有一段代码:

    public static void Sort(int N, int k, int[][] books) {
TreeMap<Integer, List<Integer>> map = new TreeMap<>();
List<List<Integer>> res = new ArrayList<>();
for (int i = 0; i < N; i++) {
int curDisorder = 0;
for (int j = 0; j < k; j++) {
for (int u = j+1; u < k; u++) {
if (books[i][j] > books[i][u]) {
curDisorder++;
}
}
}
map.put(curDisorder, new ArrayList<>(Arrays.asList(books[i])));
}
for (ArrayList<Integer> list: map.values) {
res.add(list);
}
System.out.print(res);
}

但是,它在 map.put() 处有错误:

method Map.put(Integer, List) is not applicable
argument mismatch: cannot infer type arguments for ArrayList<>
reason: inference variable E has incompatible bounds

这段代码有什么问题?

最佳答案

我认为你必须为你的 Arraylist 输入集合类型:

map.put(curDisorder, new ArrayList<Integer>(Arrays.asList(books[i])));

关于java - 找不到适合 put(int, ArrayList) 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55427663/

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