0

So i learned on how to, arrange my arrays in ascending order, but now im stuck finding ways on how to get my arrays in descending order.

so far this is my code:

    import java.util.Collections;
    import java.util.Arrays;

    public class arrays {
    public static void main(String args[]){
    int arrays[]={4,3,8,9,0,44,12};

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

    for(int i=0;i<arrays.length;i++){
        System.out.print(arrays[i]);
    }
  }
}

But my IDE(Eclipse) says that there is an error on "Arrays.sort(arrays, Collections.reverseOrder());" which i cant figure out. help please.

Muffin
  • 1
  • 2
  • 2
    When you get an error message, never just say "there is an error". The error message contains important information about what's wrong. Read and try to understand the error message. If you don't understand it, post the exact error message in your question, so people can tell you what it means. So, what is the error that you get? – Jesper Jun 16 '16 at 08:49
  • try this List integersList = Ints.asList(arrays); // Change First as List Type Collections.sort(integersList, Collections.reverseOrder()); //Now use Collections Class To Sort the Arrays. – Vikrant Kashyap Jun 16 '16 at 09:01
  • @Muffin Duplicate of: [Sorting int array in descending order](http://stackoverflow.com/q/7414299/876298) – Alex K Jun 16 '16 at 09:01

1 Answers1

1

Arrays.sort(T[] a, Comparator c) doesn't work with primitive types arrays.

You may simply change your array, to an array of Integer :

Integer arrays[]={4,3,8,9,0,44,12};
Arnaud
  • 17,229
  • 3
  • 31
  • 44