Guava Ordering 使用

 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()+" ");
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值