数组降序排列
是不是非primitive types类型的数据才能用第十一章的对象的集合中讲的泛型来解决?primitive types类型的数组貌似不行
public class Hello { public static void main(String[] args) { int a[] = {1, 3, 2, 6, 4}; Arrays.sort(a, Collections.reverseOrder()); for (int i=0; i<a.length; ++i) System.out.print(a[i] + " "); }}
import java.util.*;class DescType implements Comparator{ public int compare(Object o1, Object o2) { Integer i = (Integer)o1; Integer j = (Integer)o2; return (i<j?1:(i==j?0:-1)); }}public class Hello { public static void main(String[] args) { Integer a[] = {1, 3, 2, 6, 4}; //Arrays.sort(a, Collections.reverseOrder());//a Arrays.sort(a, new DescType()); //b for (int i=0; i<a.length; ++i) System.out.print(a[i] + " "); }}