I want to sort an ArrayList of ArrayList. How can I use custom comparator in Collections.sort(); ??? my IDE shows error
ArrayList<ArrayList<Integer>> A
Collections.sort(A,new Comparator<ArrayList<Integer>>(){ });
the above code is not working
I want to sort an ArrayList of ArrayList. How can I use custom comparator in Collections.sort(); ??? my IDE shows error
ArrayList<ArrayList<Integer>> A
Collections.sort(A,new Comparator<ArrayList<Integer>>(){ });
the above code is not working
If you want a single sorted list you can try this :
ArrayList<ArrayList<Integer>> myListOfList = new ArrayList<>();
List<Integer> sortedList = myListOfList.stream()
.flatMap(List::stream)
.sorted(Integer::compareTo)
.collect(Collectors.toList());
or this :
List<Integer> sortedList = myListOfList.stream()
.flatMap(List::stream)
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());