Java Array Concatenate concatenateArray(Object[] srcOne, Object[] srcTwo)

Here you can find the source of concatenateArray(Object[] srcOne, Object[] srcTwo)

Description

Concatenate two arrays.

License

Open Source License

Parameter

Parameter Description
srcOne array to concatenate
srcTwo array to concatenate

Return

concatenated array

Declaration

public static Object[] concatenateArray(Object[] srcOne, Object[] srcTwo) 

Method Source Code

//package com.java2s;
/*//  w  w  w  . j a v a  2  s. c om
 * *************************************************************************************
 *  Copyright (C) 2008 EsperTech, Inc. All rights reserved.                            *
 *  http://esper.codehaus.org                                                          *
 *  http://www.espertech.com                                                           *
 *  ---------------------------------------------------------------------------------- *
 *  The software in this package is published under the terms of the GPL license       *
 *  a copy of which has been included with this distribution in the license.txt file.  *
 * *************************************************************************************
 */

import java.util.*;

public class Main {
    /**
     * Concatenate two arrays.
     * @param srcOne array to concatenate
     * @param srcTwo array to concatenate
     * @return concatenated array
     */
    public static Object[] concatenateArray(Object[] srcOne, Object[] srcTwo) {
        Object[] result = new Object[srcOne.length + srcTwo.length];
        System.arraycopy(srcOne, 0, result, 0, srcOne.length);
        System.arraycopy(srcTwo, 0, result, srcOne.length, srcTwo.length);
        return result;
    }

    /**
     * Concatenate multiple arrays.
     * @param more arrays to concatenate
     * @return concatenated array
     */
    public static Object[] concatenateArray(Object[]... more) {
        List list = new ArrayList();
        for (int i = 0; i < more.length; i++) {
            for (int j = 0; j < more[i].length; j++) {
                list.add(more[i][j]);
            }
        }
        return list.toArray();
    }
}

Related

  1. concatenate(Object[] collection)
  2. concatenate(String[] args)
  3. concatenate(String[] strings, String sep)
  4. concatenate(T[] first, T[] second)
  5. concatenate2Arrays(T[] array1, T... array2)
  6. concatenateArrays(T[] first, T[]... rest)
  7. concatenateStrings(Object[] strings, String glueString)
  8. concatIntArrays(final int[] l1, final int[] l2)
  9. concatStrings(String[] strs, String delimiter)