(Java 8) I have an ArrayList of ArrayLists as follows:
[5, 10]
[2, 11]
[1, 12]
[8, 13]
I want these lists to be sorted by the first value in the list in either ascending or descending order. For example, with ascending order, the ArrayList would be ordered as:
[1, 12]
[2, 11]
[5, 10]
[8, 13]
How can I do this?
I am struggling with using the comparator class. Other documentation I have seen refers to when this data is represented by an array, (Arrays.sort then defining a comparator in the argument), but when it is a List of ArrayLists I cannot figure out the solution.