Ordering I read many times in Chinese documents, add some examples finally figure out what's going on.
What's he doing? Just like his name, used to ordering sort. 、
There are two main ways of doing this.
1 is sorted by its static method. such as Ordering.natural (); make a natural sort of sortable type, such as number by size, date by order. Natual () The official interpretation of the translation.
2 Ordering defined by oneself
For example, you want to sort by the length of the string.
Public voidOrderbasedonlength () {Ordering<String> bylength =NewOrdering<string>() {@Override Public intCompare (string s1, string s2) {returnInts.compare (S1.length (), s2.length ()); } }; List<String> Toorder =NewLists.newarrarylist ("Hahah", "EN" ); //here is the static method called ordering, such as natural reverse, etc.Collections.sort (Toorder, Bylength.natural (). reverse ()); System.out.println (Toorder);
For more information, refer to: http://www.leveluplunch.com/java/examples/guava-ordering-example/#reverse-elements
Google Guava Study record "three" ordering