package com.njcn.web.utils;

import cn.hutool.core.collection.CollectionUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * pqs
 *
 * @author cdf
 * @date 2022/2/28
 */
public class GeneralUtil {

    /**
     * 按指定大小，分隔集合，将集合按规定个数分为n个部分
     * @author cdf
     * @date 2021/10/26
     */
    public static List<List<String>> splitList(List<String> list, int len){
        if(CollectionUtil.isEmpty(list) || len<1){
            return null;
        }
        List<List<String>> result = new ArrayList<>();
        int size = list.size();
        int count = (size+len-1)/1000;
        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;
    }
}
