直接看代码吧,有注释
package com.ep.crm.task;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Test {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
Random random = new Random();
for (int i = 0; i < 100; i++) {
int randomNumber = random.nextInt();
list.add(String.valueOf(randomNumber));
}
while (!list.isEmpty()) {
System.out.println("原本" + list);
int batchSize = Math.min(50, list.size());
List<String> firstBatch = new ArrayList<String>(list.subList(0, batchSize));
list.subList(0, batchSize).clear();
System.out.println("取出的数据" + firstBatch);
System.out.println("取完剩余数据" + list);
}
}
}