1. 程式人生 > >切分 拆分集合list的方式

切分 拆分集合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條;