我有一段代码:
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
此代码有什么问题?
答案 0 :(得分:5)
我认为您必须将Arraylist的集合类型放在其中:
map.put(curDisorder, new ArrayList<Integer>(Arrays.asList(books[i])));