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++; } } }
结果: