java - 没有找到适合 put(int, ArrayList) 的方法
问题描述
我有一段代码:
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])));
推荐阅读
- powerbi - 如何按类别计算“整数”数据类型列的平均值
- websphere - 如何使用 liberty-maven-plugin“运行”目标以调试模式启动 Open Liberty 服务器?
- ruby-on-rails - Rails Rufus 调度程序持久性
- android - 为什么除非设置图标,否则奥利奥上的通知不会显示
- javascript - 无法在阿波罗服务器上下文中获取会话?
- google-chrome - 谷歌电子表格上的图形错误
- laravel - 未定义的方法“尝试”。在 laravel 版本 = '7.30.4'
- javascript - Expo-Updates 在弹出的反应本机项目上给出错误,如何解决?
- reactjs - MDXRenderer - 自动调整图像到容器
- javascript - 如何克隆表单并不止一次更改其子项的 id?