Java 排序比较器不起作用
Java comparator for sorting not working
默认排序方法在 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>(){})"
我觉得我现在很傻
没有 方法可以使用Arrays.sort
以默认顺序以外的任何顺序对int[]
进行排序。您可以使用任意 Comparator
对 Integer[]
进行排序,但无法为 int[]
.
自定义排序
默认排序方法在 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>(){})"
我觉得我现在很傻
没有 方法可以使用Arrays.sort
以默认顺序以外的任何顺序对int[]
进行排序。您可以使用任意 Comparator
对 Integer[]
进行排序,但无法为 int[]
.