目的:
拆分list,做到批量插入
代码
//拆分list
public static <T> List<List<T>> averageAssign(List<T> source, int len) {
List<List<T>> result = new ArrayList<>();
if (source == null || source.size() == 0 || len < 1) return result;
int size = source.size();
int count = size / len + (size % len > 0 ? 1 : 0);
for (int i = 0; i < count; i++) {
List<T> subList = source.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
result.add(subList);
}
return result;
}