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; }