/* package whatever; // don't place package name! */ import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { final int elements = 50; getList(elements), getList(elements), getList(elements), getList(elements), getList(elements)); intReversed = intReversed.reversed(); for(int i = 1; i < list.size(); i++) { final int iCopy = i; comp = comp.thenComparing(l -> l.get(iCopy), intReversed); } list.sort(comp); } public static List<Integer> getList(int elements) { return ThreadLocalRandom.current().ints(elements, 0, 10).boxed().collect(Collectors.toList()); } }
Standard input is empty
[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]