fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.Arrays;
  4. import java.util.Comparator;
  5. import java.util.List;
  6. import java.util.concurrent.ThreadLocalRandom;
  7. import java.util.stream.Collectors;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main(String[] args) {
  13. final int elements = 50;
  14. List<List<Integer>> list = Arrays.asList(
  15. getList(elements),
  16. getList(elements),
  17. getList(elements),
  18. getList(elements),
  19. getList(elements));
  20.  
  21. Comparator<Integer> intReversed = Integer::compare;
  22. intReversed = intReversed.reversed();
  23.  
  24. Comparator<List<Integer>> comp = Comparator.comparing(l -> l.get(0), intReversed);
  25. for(int i = 1; i < list.size(); i++) {
  26. final int iCopy = i;
  27. comp = comp.thenComparing(l -> l.get(iCopy), intReversed);
  28. }
  29.  
  30. list.sort(comp);
  31. list.forEach(System.out::println);
  32. }
  33.  
  34. public static List<Integer> getList(int elements) {
  35. return ThreadLocalRandom.current().ints(elements, 0, 10).boxed().collect(Collectors.toList());
  36. }
  37. }
Success #stdin #stdout 0.26s 34332KB
stdin
Standard input is empty
stdout
[8, 8, 1, 2, 2, 8, 7, 9, 5, 1, 2, 9, 1, 2, 8, 3, 7, 3, 9, 8, 8, 1, 6, 6, 6, 8, 8, 4, 8, 9, 7, 8, 2, 2, 7, 4, 7, 4, 5, 0, 1, 2, 9, 6, 3, 2, 6, 9, 4, 0]
[7, 1, 2, 0, 4, 9, 7, 3, 9, 0, 9, 6, 4, 2, 6, 8, 6, 5, 3, 1, 3, 8, 4, 7, 0, 0, 2, 2, 6, 4, 3, 1, 3, 8, 4, 2, 8, 9, 7, 7, 3, 9, 2, 0, 9, 8, 8, 9, 0, 4]
[5, 6, 8, 8, 8, 4, 7, 9, 5, 3, 9, 1, 1, 3, 2, 7, 5, 3, 2, 7, 7, 0, 2, 4, 4, 0, 4, 8, 0, 9, 1, 5, 6, 1, 6, 1, 8, 1, 7, 3, 7, 9, 6, 6, 2, 3, 2, 9, 6, 6]
[5, 0, 3, 8, 6, 3, 8, 8, 4, 6, 8, 6, 8, 4, 7, 2, 9, 3, 8, 6, 3, 5, 0, 0, 3, 8, 9, 2, 7, 5, 8, 5, 3, 7, 2, 5, 0, 3, 4, 0, 0, 6, 8, 0, 0, 0, 5, 7, 2, 9]
[2, 6, 8, 8, 2, 5, 6, 6, 8, 5, 4, 3, 0, 6, 7, 4, 1, 9, 5, 9, 8, 4, 7, 5, 4, 2, 4, 5, 1, 0, 0, 9, 1, 4, 0, 0, 7, 1, 0, 6, 8, 5, 2, 2, 8, 1, 9, 4, 7, 8]