Java Array Merge mergeArrays(Object[] first, Object[] second)

Here you can find the source of mergeArrays(Object[] first, Object[] second)

Description

Merges two Array to one.

License

Open Source License

Parameter

Parameter Description
first - The first Array.
second - The Second Array.

Return

- A new Array from thos merged Arrays: Warning: You must cast every single Object inside the array to your class.

Declaration

public static Object[] mergeArrays(Object[] first, Object[] second) 

Method Source Code

//package com.java2s;
/******************************************************************************
 *
 * AniDBCmdC version 1.0 - AniDB client in Java
 * Copyright (C) 2005 ExElNeT//from   w  w  w  .  ja v  a2 s .  c  om
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * E-mail: exelnet@web.de
 *
 *******************************************************************************/

public class Main {
    /**
     * Merges two Array to one.
     * 
     * @param first -
     *            The first Array.
     * @param second -
     *            The Second Array.
     * @return - A new Array from thos merged Arrays: Warning: You must cast
     *         every single Object inside the array to your class.
     */
    public static Object[] mergeArrays(Object[] first, Object[] second) {
        if (first != null && second == null)
            return first;
        if (first == null && second != null)
            return second;
        if (first != null && second != null) {
            int size = first.length + second.length;
            Object[] newObjectArray = new Object[size];
            for (int i = 0; i < first.length; i++)
                newObjectArray[i] = first[i];
            for (int i = 0; i < second.length; i++)
                newObjectArray[first.length + i] = second[i];
            return newObjectArray;
        }
        return null;
    }
}

Related

  1. mergeArrays(final byte[] buf1, final byte[] buf2)
  2. mergeArrays(final Object[] a1, final Object[] a2, final Object[] merge)
  3. mergeArrays(int[] theArrayA, int[] theArrayB)
  4. mergeArrays(long[] alldistances, long[] currentUserDistances)
  5. mergeArrays(Object[] arr1, Object[] arr2, Object[] destinationArray)
  6. mergeArrays(String[] a, String[] b)
  7. mergeArrays(String[] a1, String[] a2)
  8. mergeArrays(String[] array, String[] newEntries)
  9. mergeArrays(String[] data1, String[] data2)