java中将一个list按照固定笔数平均分成若干个list
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("正好整批处理成功"); } }