1, basic rules
1.0 let your class implements comparable interface, override Method:int CompareTo (Object another)
1.1 Ascending obj1 > Obj2 return positive
Obj1 = = Obj2 return 0
Obj1 < OBJ2 return negative
1.2 Descending is the opposite of ascending order
1.3 If class already implements comparable interface, the comparison algorithm defined when sorted with the sort method of the collections class takes effect and can also be called: public static <T> void sort (list<t> List, comparator<? Super T> Comparator), passing a Comparator for custom sorting
2,comparable and Comparator differences
2.0 The former CompareTo has only one parameter, which allows the inner elements of the class to be compared with the parameters: int CompareTo (Object another)
The latter has two parameters, which are compared externally: int compare (t LHS, t RHS);
2.1 Position:
Comparable:java.lang
Comparator:java.util
Comparable a custom ascending/descending sort of a class with a comparator