在工作中我们可能会遇到很多的list拆分,拆分的作用基本都是为了分批处理提高效率,在这里写了一个自己使用的工具类给大家参考
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import java.util.List;
/**
* 拆分结合工具类
*
* @author cabbageDevil
* @date 2022/1/27
*/
public class SplitListUtils {
/**
* 拆分集合
*
* @param <T> 泛型对象
* @param resList 需要拆分的集合
* @param subListLength 每个子集合的元素个数
* @return 返回拆分后的各个集合组成的列表
* 代码里面用到了guava和common的结合工具类
**/
public static <T> List<List<T>> split(List<T> resList, int subListLength) {
if (CollectionUtils.isEmpty(re