private List<List<EbizCustomerPushDTO>> splitList(List<EbizCustomerPushDTO> list , int groupSize){
int length = list.size();
// 计算可以分成多少组
int num = ( length + groupSize - 1 )/groupSize ; // TODO
List<List<EbizCustomerPushDTO>> newList = new ArrayList<List<EbizCustomerPushDTO>>();
for (int i = 0; i < num; i++) {
// 开始位置
int fromIndex = i * groupSize;
// 结束位置
int toIndex = (i+1) * groupSize < length ? ( i+1 ) * groupSize : length ;
newList.add(list.subList(fromIndex,toIndex)) ;
}
return newList ;
}
按照长度切割list集合
最新推荐文章于 2024-05-11 16:01:35 发布