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