数据分批拆分

数据分批拆分

public class ThreadUtil {
   /**
    * 数据分批拆分
    * 
    * @param
    * @param batchCount
    * @return
    */
   public static List> batchList(List urls, int batchCount) {
      // 分批初始值
      int batchLastIndex = batchCount;
      int size = urls.size();
      List> batchList = new ArrayList>();
      for (int index = 0; index < size;) {
         if (batchLastIndex >= size) {
            batchLastIndex = size;
            batchList.add(urls.subList(index, batchLastIndex));
            break;
         }

         batchList.add(urls.subList(index, batchLastIndex));
         index = batchLastIndex;// 设置下一批下标
         batchLastIndex = index + batchCount;
      }
      return batchList;
   }
}

你可能感兴趣的:(java,windows,开发语言)