List split

功能:

将List切分为指定大小的List组

源码:

public static  List> split(List srcList, int groupSize) {
        int mod = srcList.size() % groupSize;
        int pou = srcList.size() / groupSize;
        int len = (mod == 0 ? pou : pou + 1);
        int n = 0;
        int start;
        
        List list = null;
        List> rlist = new ArrayList>();
        
        for (int i = 0; i < len; i++) {
            if(i == pou) {
                n = mod;
            } else {
                n = groupSize;
            }
            list = new ArrayList(n);
            start = i * groupSize;
            for (int k = 0; k < n; k++) {
                list.add(srcList.get(start + k));
            }
            rlist.add(list);
        }
        return rlist;
    }

你可能感兴趣的:(List split)