如何对一个基本的数据类型的数组从大到小的排序
Arrays中的sort方法是不是一定要把基本的数据类型改为它对应的封装类在用实现比较接口才能实现啊有没有更简洁的方法`~~

解决方案 »

  1.   

    write you own code. Why must you use API's class.
      

  2.   

    楼主看一下api文档就可以了,要从大到小应该是要把int转成Integer才行的吧
    static void sort(byte[] a) 
              Sorts the specified array of bytes into ascending numerical order. 
    static void sort(byte[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of bytes into ascending numerical order. 
    static void sort(char[] a) 
              Sorts the specified array of chars into ascending numerical order. 
    static void sort(char[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of chars into ascending numerical order. 
    static void sort(double[] a) 
              Sorts the specified array of doubles into ascending numerical order. 
    static void sort(double[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of doubles into ascending numerical order. 
    static void sort(float[] a) 
              Sorts the specified array of floats into ascending numerical order. 
    static void sort(float[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of floats into ascending numerical order. 
    static void sort(int[] a) 
              Sorts the specified array of ints into ascending numerical order. 
    static void sort(int[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of ints into ascending numerical order. 
    static void sort(long[] a) 
              Sorts the specified array of longs into ascending numerical order. 
    static void sort(long[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of longs into ascending numerical order. 
    static void sort(Object[] a) 
              Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. 
    static void sort(Object[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. 
    static void sort(short[] a) 
              Sorts the specified array of shorts into ascending numerical order. 
    static void sort(short[] a, int fromIndex, int toIndex) 
              Sorts the specified range of the specified array of shorts into ascending numerical order. 
    static <T> void 
     sort(T[] a, Comparator<? super T> c) 
              Sorts the specified array of objects according to the order induced by the specified comparator. 
    static <T> void 
     sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) 
              Sorts the specified range of the specified array of objects according to the order induced by the specified comparator. 
      

  3.   

    import java.util.*;public class Reverse {
    public static void main(String args[]){
    int a[] = new int[5];
    Integer aa[] = new Integer[a.length];
    Random rnd = new Random();
    for(int i=0; i<a.length; i++){
    a[i] = rnd.nextInt();
    aa[i] = new Integer(a[i]);
    }

    Arrays.sort(aa,Collections.reverseOrder());

    for(int i=0; i<a.length; i++){
    System.out.println(aa[i]);
    }
    }
    }