Here you can find the source of divideIntoChunks(Object[] objs, int chunkSize)
public static Object[][] divideIntoChunks(Object[] objs, int chunkSize)
//package com.java2s; /**//w w w . java 2 s .co m * Copyright 2001-2014 CryptoHeaven Corp. All Rights Reserved. * * This software is the confidential and proprietary information * of CryptoHeaven Corp. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with CryptoHeaven Corp. */ public class Main { /** * Divides an array of Objects into series of smaller arrays. */ public static Object[][] divideIntoChunks(Object[] objs, int chunkSize) { Object[][] chunkObjs = null; if (objs == null || objs.length == 0) { chunkObjs = new Object[0][]; } else { int chunks = ((objs.length - 1) / chunkSize) + 1; chunkObjs = new Object[chunks][]; int count = 0; int batchCount = 0; while (count < objs.length) { int bunch = Math.min(chunkSize, objs.length - count); Object[] bunchObjs = new Object[bunch]; for (int i = 0; i < bunch; i++) { bunchObjs[i] = objs[count + i]; } chunkObjs[batchCount] = bunchObjs; batchCount++; count += bunch; } } return chunkObjs; } }