Java - 搬砖 - 按数量切割集合

    private static void test1(List<Long> list) {
        int size = 10;
        List<List<Long>> listArr = new ArrayList<>();

        int arrSize = list.size() % size == 0 ? list.size() / size : list.size() / size + 1;
        for (int i = 0; i < arrSize; i++) {
            List<Long> sub = new ArrayList<>();
            for (int j = i * size; j <= size * (i + 1) - 1; j++) {
                if (j <= list.size() - 1) {
                    sub.add(list.get(j));
                }
            }
            listArr.add(sub);
        }
        System.out.println(listArr.toString());
    }

 

posted @ 2020-12-28 01:43  雾中的-松  阅读(195)  评论(0编辑  收藏  举报