java 实现每次从list中取5000条数据放入新list
作者:互联网
public static <T> List<List<T>> split(List<T> resList, int count) { if (resList == null || count < 1) return null; List<List<T>> ret = new ArrayList<List<T>>(); int size = resList.size(); if (size <= count) { // 数据量不足count指定的大小 ret.add(resList); } else { int pre = size / count; int last = size % count; // 前面pre个集合,每个大小都是count个元素 for (int i = 0; i < pre; i++) { List<T> itemList = new ArrayList<T>(); for (int j = 0; j < count; j++) { itemList.add(resList.get(i * count + j)); } ret.add(itemList); } // last的进行处理 if (last > 0) { List<T> itemList = new ArrayList<T>(); for (int i = 0; i < last; i++) { itemList.add(resList.get(pre * count + i)); } ret.add(itemList); } } return ret; }
标签:count,5000,java,int,list,ret,add,itemList,resList 来源: https://www.cnblogs.com/winddogg/p/10920076.html