List集合分批处理
import java.util.ArrayList;
import java.util.List;
public class ListSplit {
public static void main(String[] args) {
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < 520; i++) {
list.add(i);
}
ListSplit.test1(list);
}
public static void test1(List<Object> dataList){
int pointsDataLimit = 50;
List<Object> newList = new ArrayList<Object>();
for(int i=0;i<dataList.size();i++){
newList.add(dataList.get(i));
if(pointsDataLimit == newList.size()||i == dataList.size()-1){
printList(newList);
newList.clear();
System.out.println("");
System.out.println("=====");
}
}
}
public static void printList(List<Object> dataList){
for(Object str : dataList){
System.out.print(str + " -- ");
}
}
}
public static void main(String[] args) {
List<Integer> dataList = new ArrayList<Integer>();
for(int i=0;i<12888;i++)
dataList.add(i);
if(null!=dataList&&dataList.size()>0){
int pointsDataLimit = 1000;
Integer size = dataList.size();
if(pointsDataLimit<size){
int part = size/pointsDataLimit;
System.out.println("共有 : "+size+"条,!"+" 分为 :"+part+"批");
for (int i = 0; i < part; i++) {
List<Integer> listPage = dataList.subList(0, pointsDataLimit);
System.out.println(listPage);
dataList.subList(0, pointsDataLimit).clear();
}
if(!dataList.isEmpty()){
System.out.println(dataList);
}
}else{
System.out.println(dataList);
}
}else{
System.out.println("没有数据!!!");
}
}