对list集合的内容分组

/**
     * 把list集合里的内容按照len大小分组
     * @param list
     * @param len
     * @return
     */
    private static List<List<String>> splitList(List<String> list, int len) {
        if (list == null || list.size() == 0 || len < 1) {
            return null;
        }
        List<List<String>> result = new ArrayList<List<String>>();
        int size = list.size();
        int count = (size + len - 1) / len;
        for (int i = 0; i < count; i++) {
            List<String> subList = list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
            result.add(subList);
        }
        return result;
    }

 

posted @ 2019-08-26 14:05  简直HA怕  阅读(3650)  评论(0编辑  收藏  举报