There is a list of objects - List<Contact> contacts = new ArrayList<Contact>(); The method that returns it:
public List<Contact> getContacts() { return contacts; } It is required to sort it in reverse order:
Collections.sort(cm.getContacts(), Collections.reverseOrder()); Throws an exception:
xception in thread "main" java.lang.ClassCastException: com.sirma.Contact cannot be cast to java.lang.Comparable at java.util.Collections$ReverseComparator.compare(Collections.java:5108) at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355) at java.util.TimSort.sort(TimSort.java:220) at java.util.Arrays.sort(Arrays.java:1512) at java.util.ArrayList.sort(ArrayList.java:1454) at java.util.Collections.sort(Collections.java:175) at com.sirma.Main.main(Main.java:77) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Please tell me how to solve the problem
contactsat least one element is? Did theContactclass implement thecompareTomethod? as? And what did you writeCollections.reverseOrder()for? - Alexey ShimanskyContactclass, nor the implementation of its methods in the current question for sorting, neither information about how full the collection, nor about other elements. - Alexey Shimansky