Java将数据进行分组处理

时间:2020-01-10 12:44:03   收藏:0   阅读:511

将传人的数据进行分组,使用map保存每组的数据。

/**
         * 将取出的数据进行分组
         * @param list
         * @return
         */
        public Map<Integer,Object> groupList(List<Map<String, Object>> list){
            int listSize=list.size();
            int toIndex=1000;
            Map<Integer,Object> map = new HashMap<Integer,Object>();     //用map存起来新的分组后数据
            Integer keyToken = 0;
            for(int i = 0;i<list.size();i+=1000){
                if(i+1000>listSize){        //作用为toIndex最后没有1000条数据则剩余几条newList中就装几条
                    toIndex=listSize-i;
                }
                List<Map<String, Object>> newList = list.subList(i,i+toIndex);
                map.put(keyToken, newList);
                keyToken++;
            }
            return map;
        }

原文:https://www.cnblogs.com/sinosoft/p/12175391.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!