List<List<Map>> splitList(List<Map> list , int groupSize){
return Lists.partition(list, groupSize); // 使用guava进行分组
}
import com.google.common.collect.Lists
工具包2
package org.apache.commons.collections4;
ListUtils.partition(List originalList,Integer batchSize)
public static <T> List<List<T>> partition(final List<T> list, final int size) {
if (list == null) {
throw new NullPointerException("List must not be null");
}
if (size <= 0) {
throw new IllegalArgumentException("Size must be greater than 0");
}
return new Partition<>(list, size);
}