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;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM