Java Array Divide divideIntoChunks(Object[] objs, int chunkSize)

Here you can find the source of divideIntoChunks(Object[] objs, int chunkSize)

Description

Divides an array of Objects into series of smaller arrays.

License

Open Source License

Declaration

public static Object[][] divideIntoChunks(Object[] objs, int chunkSize) 

Method Source Code

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

Related

  1. divideElements_Bcol(int j, int numRows, int numCols, double[] u, double b[], int startB, double u_0)
  2. divideElementwise(int[] a, int[] b)
  3. divideImage(float[][] base, float[][] divisor)
  4. divideInPlace(double denominator, double[] target)
  5. divideInPlace(float[] vector, float val)
  6. divideNonSingular(int[] array1, int[] array2)
  7. divideVector(float[] resultVec, float divisor)
  8. divideVectors(float[] v1, float[] v2)
  9. divisors(final int n, final int[] buffer)