记录一次List Map 排序

 

Collections 进行排序 
List<Map<String, Object>> mapList = baseMapper.selectMaxScore(userId);
        Collections.sort(mapList,new Comparator<Map<String,Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Double s = Double.parseDouble(o1.get("score").toString());//由于从map里面取出来的值为Object类型,无法直接转换为Integer类型,需要转换为double
                Double d = Double.parseDouble(o2.get("score").toString());
                Double D1 = new Double(s);  //由于double类型无法直接转换为Integer类型,需要用封装类先封装double
                Double D2 = new Double(d);
                Integer s1 = D1.intValue();  //使用Double的intValue方法转换为Integer类型
                Integer s2 = D2.intValue();                //使用Entry类中的值来比较大小
                return s2.compareTo(s1);  //s1在前面是升序,s1在后面是降序//              //使用Entry类中的键来比较大小
//              return o2.getKey().compareTo(o1.getKey());
            }});
        Double dx = 0D;
        if(!mapList.isEmpty()){
           dx =  (Double) mapList.get(0).get("score");
        }
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值