As per Documentation: -
Code:
sort(List<T> list, Comparator<? super T> c)
1. The first argument is the list which need to be sorted
2. The second argument is the object of class implementing Comparator interface. This will determine the ordering of the elements in your list.
you can use this too "sort(List<T> list)", but in that case the elements of the list should be comparable, i.e. they should implement Comparable interface and their comparison done by compareTo method should not throw ClassCastException
Bookmarks