聚合一下使用挺方便的分批方式,后续查找回顾方便
提供思路
/**
* 切割数据集合
*
* @param list 待切割集合
* @param len 集合按照多大size来切割
* @return
*/
public static List<List<T>> groupList(List<T> list, int len) {
if (list == null || list.isEmpty() || len < 1) {
return null;
}
List<List<T>> listGroup = new ArrayList<>();
int size = list.size();
int count = (size + len - 1) / len;
for (int i = 0; i < count; i++) {
List<T> subList = list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
listGroup.add(subList);
}
return listGroup;
}
//调用 切割数据集合
//List> groupDataList = groupList(dataList, 500);
//import com.google.common.collect.Lists;
//根据指定ID查询规则
List<QaRuleDto> rules = new ArrayList<>();
List<List<QaRuleDto>> newList = Lists.partition(rules , 10);
for (List<QaRuleDto> ruleDtoList : newList) {
for (QaRuleDtoruleDto : ruleDtoList) {
//TODO 逻辑处理
}
}
List<Integer> list=new ArrayList<>();
for (int i=0;i<500;i++){
list.add(i);
}
List<List<Integer>> newList = Lists.partition(list, 150);
for (List<Integer> list1:newList){
System.out.println(list1.size());
}
<dependency>
<groupId>com.google.guavagroupId>
<artifactId>guavaartifactId>
<version>23.0version>
dependency>