切分 拆分集合list的方式

时间:2023-03-09 22:45:55
切分 拆分集合list的方式

一般有两种,第一是sublist(),代码冗余效率低;

第二种:

引包自

com.google.common.collect.Lists

话不多说直接上实例:
List<ContractModel> contractList = ****;
List<List<ContractModel>> partition = Lists.partition(contractList, Constants.BATCH_SIZE);
for (List<ContractModel> item : partition){
contractModelDao.updateContractBatch(item);
} 注:
updateContractBatch 是个批量方法;
Constants.BATCH_SIZE 50条;