How to sort ArrayList ascending descending order
Sorting ArrayList in
Java is not difficult, by using Collections.sort()
method you can sort
ArrayList in ascending and
descending order in Java. Collections.sort() the method optionally accepts a Comparator and if provided it uses Comparator's
compare method to compare Objects stored in Collection to compare with each
other, in case of no explicit Comparator, Comparable interface's compareTo() method is used to compare
objects from each other. If objects stored in ArrayList
don't implement Comparable
then they can not be sorted using Collections.sort() the method in Java.