3 Kinds of sorting
TreeSet <t>: Sort: You must implement the java.lang.Comparable interface in the class <T> to which the object belongs, and override the Tocompare () method.
List <t>+ Collection Tool class:
- Collections.sort (list): You need to implement the comparable interface and override the Tocompare () method.
- Collections.sort (list,new Comparator () {@Override public int compare (object o01, Object o02) ...}); Object classes do not implement interfaces.
2 Methods of reverse output
Collections Tool Reverse Output element:
- Collections.sort (list, Collections.reverseorder ()); Descending arrangement;
- comparator<person> Desccomparator = Collections. Reverseorder (Asccomparator); //Sort objects in ascending order to produce a reversed (descending) Sort object
some other common API functions are:
collections.reverse (list); reverse sort.
string Property ordering can be used in the following ways
public int compareTo (Cat o) {return this.getname (). CompareTo (O.getname ());}
Comparetto ()
The string property ordering takes Collections.sort (list, string.case_insensitive_order);
Java Collection Sorting issues