170809、 把list集合中的数据按照一定数量分组

/**
     * @Desc :  切分list位多个固定长度的list集合(我这是业务需要,直接是1w条数据切分)
     * @Author : RICK
     * @Params: [historyList]
     * @Return: java.util.Map
     * @Date : 2017/10/26 18:30
     */
    public static Map spiltList(List<CsvVo> historyList) {
        int listSize = historyList.size();
        int toIndex = 10000;
        Map map = new HashMap();     //用map存起来新的分组后数据
        int keyToken = 0;
        for (int i = 0; i < historyList.size(); i += toIndex) {
            if (i + toIndex > listSize) {        //作用为toIndex最后没有100条数据则剩余几条newList中就装几条
                toIndex = listSize - i;
            }
            List newList = historyList.subList(i, i + toIndex);
            map.put(keyToken, newList);
            keyToken++;
        }
        System.out.println("一共切分了" + map.size() + "个list");
        return map;
    }

 

posted @ 2017-10-26 18:31  目标奔雷手  阅读(5503)  评论(0编辑  收藏  举报