Exercise – Sort list of objects
Name two methods that allow sorting a list of objects, and the prerequisites for their use.
Answer
Two static methods of the class java.util.Collections:
void sort(List<T> list): Sorts a list of objects that implement the interfaceComparable(thecompareTo(T)method),void sort(List<T> list, Comparator<T> comparator): Sorts objects according to theComparatorprovided (thecompare(T o1, T o2)method)