Reputation: 33
How can I sort an array and print the values in descending order?
say the example array is: ["1a","1b","1c"]
they have numbers before the first character alphabet values, i want to print:
1c
1b
1a
Upvotes: 3
Views: 137
Reputation: 2424
What you are asking is to sort an array in reverse order.
Basically you do this by reversing Arrays.sort() which is ascending.
String [] testArray = {"1a", "1b", "1c"};
Arrays.sort(testArray, Collections.reverseOrder());
for (String str : testArray) {
System.out.println(str);
}
Output is,
1c
1b
1a
You can test this here, https://ideone.com/q1OGBD.
Upvotes: 4