OnJava8-Examples/arrays/Reverse.java

34 lines
1.1 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// arrays/Reverse.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-06-15 17:47:35 -07:00
// The Collections.reverseOrder() Comparator
import java.util.*;
import onjava.*;
2015-06-15 17:47:35 -07:00
public class Reverse {
public static void main(String[] args) {
CompType[] a = Generated.array(
new CompType[12], CompType.generator());
2015-11-03 12:00:44 -08:00
System.out.println("before sorting:");
System.out.println(Arrays.toString(a));
2015-06-15 17:47:35 -07:00
Arrays.sort(a, Collections.reverseOrder());
2015-11-03 12:00:44 -08:00
System.out.println("after sorting:");
System.out.println(Arrays.toString(a));
2015-06-15 17:47:35 -07:00
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
before sorting:
[[i = 58, j = 55], [i = 93, j = 61], [i = 61, j = 29]
, [i = 68, j = 0], [i = 22, j = 7], [i = 88, j = 28]
, [i = 51, j = 89], [i = 9, j = 78], [i = 98, j = 61]
, [i = 20, j = 58], [i = 16, j = 40], [i = 11, j = 22]
]
after sorting:
[[i = 98, j = 61], [i = 93, j = 61], [i = 88, j = 28]
, [i = 68, j = 0], [i = 61, j = 29], [i = 58, j = 55]
, [i = 51, j = 89], [i = 22, j = 7], [i = 20, j = 58]
, [i = 16, j = 40], [i = 11, j = 22], [i = 9, j = 78]
]
2015-09-07 11:44:36 -06:00
*/