【发布时间】:2017-06-23 23:23:17
【问题描述】:
默认排序方法在 Java 中不适合我。
int[] nums = {11,14,15,10};
Arrays.sort(nums, new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
// compare code here
}
});
我得到的错误是
"The method sort(int[]) in the type Arrays is not applicable for the arguments (int[], new Comparator<Integer>(){})"
我觉得我现在很愚蠢。
【问题讨论】:
-
int[]不是Integer[],int不是Integer。 -
您不能指定 Comparator 以通过
Arrays.sort对 int[] 进行排序。 -
也许更具体地说是stackoverflow.com/questions/12654600/descending-order。假设世界上有人在过去的某个时候遇到过与您相同的问题并从那里开始工作。
标签: java sorting comparator