package com.qunar.piao.sight.common.util; import com.google.common.annotations.GwtCompatible; import org.apache.xmlbeans.impl.xb.xsdschema.Public; import java.util.Collection; import java.util.List; /** * Created by yubin.qi on 2015/4/15. */ public class SubListUtil { //Function<? super F, ? extends T> public static interface SubListFuntion<T> { public void processor(List<T> tList); } public static <T> void dealForSubList(List<T> totalList, Integer subSize, SubListFuntion<T> subFuntion) { int count = totalList.size(); int iteratorCount = count / subSize; for (int i = 0; i <= iteratorCount; i++) { int endIndex, startIndex; startIndex = i * subSize; endIndex = ((endIndex = (i + 1) * subSize) > count) ? count : endIndex; if (endIndex == startIndex) { break; } List<T> subList = totalList.subList(startIndex, endIndex); //dataPre subFuntion.processor(subList); } } public static void main(String args[]) { List<String> as = null; SubListUtil.dealForSubList(as, 1000, new SubListFuntion<String>() { @Override public void processor(List<String> strings) { } }); } }
本文出自 “程序猿De香蕉” 博客,请务必保留此出处http://qiyubin.blog.51cto.com/3642349/1642185
原文地址:http://qiyubin.blog.51cto.com/3642349/1642185