我有一段代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
但是,它在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
Run Code Online (Sandbox Code Playgroud)
此代码有什么问题?
小智 5
我认为您必须为您的Arraylist放入集合类型:
map.put(curDisorder, new ArrayList<Integer>(Arrays.asList(books[i])));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |