JAVA 每次从List中取出100条记录

方法一:

int listSize = customerIdList.size();
int toIndex = 1000;
for(int i = 0; i < customerIdList.size(); i += 1000){
   if(i + 1000 > listSize) {
      toIndex = listSize - i;
} List<String> idList = customerIdList.subList(i, i + toIndex); }

方法二:

//每1000一批,分批处理
int batchCount = 1000;
int sourListSize = customerIdList.size();
int subCount = sourListSize % batchCount == 0 ? sourListSize / batchCount : sourListSize / batchCount + 1;
int startIndext = 0;
int stopIndext = 0;
for (int i = 0; i < subCount; i++) {
     stopIndext = (i == subCount - 1) ? stopIndext + sourListSize % batchCount : stopIndext + batchCount;
     List<String> idList = new ArrayList<>(customerIdList.subList(startIndext, stopIndext));
     startIndext = stopIndext;
}