public static void main(String[] args) {
// Ordering.from(Comparator.comparing())
List<String> list = Lists.newArrayList("10","2","5");
String min = Ordering.from(Comparator.comparingInt((String s) -> Integer.valueOf(s))).min(list);
System.out.println(min);
// 对集合中元素调用Function,再按返回值用当前排序器排序。
Ordering<FastCode> ordering = Ordering.natural().nullsFirst().onResultOf(new Function<FastCode, String>() {
public String apply(FastCode foo) {
return foo.getMeaning();
}
});
FastCode fastCode = new FastCode();
fastCode.setMeaning("11");
FastCode fastCode2 = new FastCode();
fastCode2.setMeaning("12");
FastCode fastCode3 = new FastCode();
fastCode3.setMeaning("13");
List<FastCode> fastCodeList = Lists.newArrayList(fastCode2,fastCode,fastCode3);
Collections.sort(fastCodeList,ordering);
for (FastCode code : fastCodeList) {
System.out.print(code.getMeaning()+" ");
}
}
Guava Ordering 使用
最新推荐文章于 2024-01-09 15:04:49 发布
649

被折叠的 条评论
为什么被折叠?



