list处理为多段

public static List batchData(List<?> inputList,int maxValue) throws Exception{
    List list=new ArrayList();
    List<object> tempList =new ArrayList<object>();
    int size = inputList.size();
    int total = size/maxValue;
    if(size % maxValue !=0){
        total +=1;
    }
    for(int i=0;i<total;i++){
        if(i==total-1){
            maxValue=size-(i*maxValue);
        }
        for (int j=0;j<maxValue;j++){
            tempList.add(inputList.get(j));
        }
        list.add(new ArrayList<object>(tempList));
        inputList.removeAll(tempList);
        tempList.clear();
    }
    return list;
}

 

list处理为多段

上一篇:Hiring Staff CodeForces - 216C


下一篇:单一计划任务(at)和循环计划任务(crontab)