JAVA 每次從List中取出100條記錄 package com.blmlove; import java.util.*; public class Test { public static void main(String[] args) { Test test = new Test(); Li ...
JAVA 每次從List中取出100條記錄
package com.blmlove; import java.util.*; public class Test { public static void main(String[] args) { Test test = new Test(); List list =new ArrayList<>(); for(int i=1;i<=1260;i++){ list.add(i); } test.groupList(list); } void groupList(List list){ int listSize=list.size(); int toIndex=1000; int keyToken = 0; for(int i = 0;i<list.size();i+=1000){ if(i+1000>listSize){ //作用為toIndex最後沒有100條數據則剩餘幾條newList中就裝幾條 toIndex=listSize-i; } List newList = list.subList(i,i+toIndex); System.out.println(newList); keyToken++; } } }
結果: