package com.zm.order.tool.server.utils;


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

/**
 * @Description list工具类
 * @Author: ph
 * @Date: 2019/12/13 11:55
 */
public class ListUtils {

    public static <T> List<List<T>> fixedGrouping2(List<T> source, int n) {

        if (null == source || source.size() == 0 || n <= 0) {
            return null;
        }
        List<List<T>> result = new ArrayList<>();
        int remainder = source.size() % n;
        int size = (source.size() / n);
        for (int i = 0; i < size; i++) {
            List<T> subset = null;
            subset = source.subList(i * n, (i + 1) * n);
            result.add(subset);
        }
        if (remainder > 0) {
            List<T> subset = source.subList(size * n, size * n + remainder);
            result.add(subset);
        }
        return result;
    }

}
