I am viewing a list of lists (in ArrayLists) using a comparator. Where is the first order. All capital letters will always be the same size.
For example, a list
[[4,5,6], [7,9,10], [4,7,8], [1,2,3], [7,9,12]]
It must
[[7,9,12], [7,9,10], [4,7,8], [4,5,6], [1,2,3]]
I have something like this, but only sorted by the first item in each list
List<List<Integer>> list = Arrays.asList(
Arrays.asList(4,5,6),
Arrays.asList(7,9,10),
Arrays.asList(4,7,8),
Arrays.asList(1,2,3),
Arrays.asList(7,9,12));
list.sort((l1, l2) -> l2.get(0).compareTo(l1.get(0)));
What produces:
[[7, 9, 10], [7, 9, 12], [4, 5, 6], [4, 7, 8], [1, 2, 3]]
How can I write a comparator that sorts by the next element in the list if the before element is equal?
For example, [7, 9, 10], [7, 9, 12] should go to a comparison of two 7, then two 9, and then 10 and 12. For example, [4, 5, 6] [4, 7, 8] must go to compare two 4, and then 4 and 7 and stop.