Ordering<String> ordering = Ordering.natural();Ordering.usingToString();
List<String>strs = Arrays.asList("dd","aa","bb","cc");
List<Integer>ints = Arrays.asList(4,3,2,11,9);
List<Integer>list1 = Lists.newArrayList(1,2,3);
List<Integer>list2=Lists.newArrayList(-1,100,4);
List<Integer>list3=Lists.newArrayList(0,98,4);
List<List<Integer>>lists = Lists.newArrayList(list1,list2,list3);
System.out.println(Ordering.<Integer>natural().lexicographical().sortedCopy(lists));
System.out.println(ordering.sortedCopy(strs));
Collections.sort(strs,Ordering.natural().nullsFirst().reversed());
System.out.println(strs);
System.out.println(Ordering.natural().nullsLast().compound(Ordering.natural()).sortedCopy(ints));
System.out.println(Ordering.natural().isOrdered(strs));
System.out.println(Ordering.natural().max(1,2,3,4));
System.out.println(Ordering.natural().max(ints));
System.out.println(Ordering.natural().greatestOf(ints,3));
System.out.println(Ordering.natural().leastOf(ints,3));
List<Person>person = Lists.newArrayList(new Person(1,"Tao"),new Person(2,"Xia"));
System.out.println(Ordering.natural().nullsFirst().reverse().onResultOf(new Function<Person, Integer>() {
public Integer apply(Person p){
return p.age;
}
}).sortedCopy(person));
Collections.sort(person, new Ordering<Person>() {
@Override
public int compare(@Nullable Person person, @Nullable Person t1) {
return ComparisonChain.start()
.compare(person.name,t1.name)
.compare(person.age,t1.age)
.result();
}
});