private static int batchSize = 3; public static void main(String[] args) { List<Integer> list = new ArrayList<>(); for(int i = 1;i<=10;i++){ list.add(i); } for(int i= 0;i < list.size() / batchSize;i++){ List<Integer> insertList = list.subList(i*batchSize, (i+1)*batchSize); System.out.println(insertList); } if(list.size() % batchSize != 0){ System.out.println("最后剩余的数据:"+list.subList((list.size() / batchSize) * batchSize, list.size())); }else{ System.out.println("正好整批处理成功"); } }
原文地址:https://www.cnblogs.com/sikuaiwu/p/12068009.html
时间: 2024-11-07 12:26:44