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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM