Java Array Combine combineArrays(final Object[] array1, final Object[] array2, final Object[] targetArray)

Here you can find the source of combineArrays(final Object[] array1, final Object[] array2, final Object[] targetArray)

Description

Combines two array into a target array, inserting all elements of the first array and then all elements of the second array in the target array.

License

Open Source License

Parameter

Parameter Description
array1 the first array to copy
array2 the second array to copy
targetArray the array to copy the two other array into; the type of this array must be suitable to accept elements from both array; the length of this array must be equal or greater than <code>array1.length + array2.length</code>

Declaration

public static void combineArrays(final Object[] array1,
        final Object[] array2, final Object[] targetArray) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from www .  ja  v a  2  s .com
     * Combines two array into a target array, inserting all elements of the
     * first array and then all elements of the second array in the target
     * array.
     *
     * @param array1 the first array to copy
     * @param array2 the second array to copy
     * @param targetArray the array to copy the two other array into; the
     * type of this array must be suitable to accept elements from both array;
     * the length of this array must be equal or greater than
     * <code>array1.length + array2.length</code>
     */
    public static void combineArrays(final Object[] array1,
            final Object[] array2, final Object[] targetArray) {
        final int lengthOfFirst = array1.length;
        int i;
        // copy first array into target array
        for (i = 0; i < lengthOfFirst; i++) {
            targetArray[i] = array1[i];
        }

        // copy second array into target array
        for (i = 0; i < array2.length; i++) {
            targetArray[i + lengthOfFirst] = array2[i];
        }
    }
}

Related

  1. combine(int[][] arr, int[] terms)
  2. combine(Object[] array1, Object[] array2, Object[] combinedArray)
  3. combine(Object[] first, Object[] last)
  4. combine(Object[] objects, String glue)
  5. combineAlpha(float[] partsAlpha, int partsN)
  6. combineArrays(float[]... arrays)
  7. combineByteArray(byte[] one, byte[] two)
  8. combineChannels(int[][] a, int[][] r, int[][] g, int[][] b, int[][] pixels)
  9. combineChunksToByteArray(byte chunks[][])