码迷,mamicode.com
首页 > 编程语言 > 详细

java stream数据分组 stream().collect(groupingBy

时间:2020-04-15 14:02:46      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:ping   ada   div   pre   hashmap   group   span   stream   shm   

List<Map<String, Object>> foreList = forecastDataDao.getcityforeresults(param);
        Map<String,List<Map<String, Object>>> timegroupby=foreList.stream().collect(groupingBy(p->p.get("citycode").toString()));
        Map<String,Map<String,List<Map<String, Object>>>> ret=new HashMap<>();
        if(timegroupby!=null){
            for(String time:timegroupby.keySet()){
                Map<String,List<Map<String, Object>>> citygroup=null;
                citygroup=timegroupby.get(time).stream().collect(groupingBy(p->DateUtil.dateToStr((Date)p.get("datatime"),"yyyyMMdd")));
                if(citygroup!=null){
                    ret.put(time,citygroup);
                }
            }
        }
        return JSONObject.toJSONString(ret);

 

java stream数据分组 stream().collect(groupingBy

标签:ping   ada   div   pre   hashmap   group   span   stream   shm   

原文地址:https://www.cnblogs.com/tiandi/p/12704557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!