1. public static <T> List<List<T>> splitList(List<T> list, int groupSize) {
    2. int length = list.size();
    3. // 计算可以分成多少组
    4. int num = (length + groupSize - 1) / groupSize;
    5. List<List<T>> newList = new ArrayList<>(num);
    6. for (int i = 0; i < num; i++) {
    7. // 开始位置
    8. int fromIndex = i * groupSize;
    9. // 结束位置
    10. int toIndex = Math.min((i + 1) * groupSize, length);
    11. newList.add(list.subList(fromIndex, toIndex));
    12. }
    13. return newList;
    14. }