1、Comparator實作
import java.util.*;
class DecentComparator implements Comparator<Integer>{
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
}
2、使用時注意必須用int的封裝類Integer才能比較
Integer[] a ={1,2,3,4};
Arrays.sort(a,new DecentComparator());