首页 > 其他 > 详细

list集合根据字段分组统计转换成map

时间:2019-12-20 11:35:19      阅读:743      评论:0      收藏:0      [点我收藏+]

前言

表格需要对数据进行统计

代码实现

    public Map getUnitStoreSum(String unitId, String billCode) {
        List store=listUnitStore(unitId, billCode);
        Map groupMap=new HashMap();
        for(int i=0;i<store.size();i++){        
            NoteStorageInfo nsi=(NoteStorageInfo) store.get(i); 
            List tempList=(List) groupMap.get(nsi.getPjmc());
            if (tempList == null) {
                tempList = new ArrayList();
                tempList.add(nsi);
                groupMap.put(nsi.getPjmc(), tempList);
            }
            else {
                tempList.add(nsi);
            }
        }
        Map sum=new HashMap();
        Iterator it = groupMap.keySet().iterator();
        while (it.hasNext()) {
            String pj = (String) it.next();
            List ns=(List)groupMap.get(pj);
            int sl=0;
            for(int i=0;i<ns.size();i++){
                NoteStorageInfo n=(NoteStorageInfo) ns.get(i);
                sl+=n.getSl();
            }
            sum.put(pj, new Integer(sl));
        }
        
        return sum;
    }

over

list集合根据字段分组统计转换成map

原文:https://www.cnblogs.com/wutongshu-master/p/12071832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!