62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
import java.util.*;
public class phototest {
public static void main(String[] args) throws IOException {
Comparator<Integer> mycmp =new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
return 1;//数组元素没有变化
//return -1//数组元素倒序了
}
};
Integer [] d = {9,8,10,90};
for(int i=0;i<d.length;i++) {
System.out.print(d[i] + " ");
}
System.out.println();
Arrays.sort(d, mycmp);
for(int i=0;i<d.length;i++) {
System.out.print(d[i] + " ");
}
System.out.println();
}
}
Comparator<Integer> mycmp =new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
return a > b ? 1 : -1;
}
};
Comparator<Integer> mycmp =new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
return a < b ? 1 : -1;
}
};