Java Array Concatenate concat(double[] first, double[] second)

Here you can find the source of concat(double[] first, double[] second)

Description

Returns a new array of size first.length + second.length, with the contents of the first array loaded into the returned array starting at the zero'th index, and the contents of the second array appended to the returned array beginning with index first.length.

License

Open Source License

Parameter

Parameter Description
first the data to load starting at index 0
second the data to load starting at index first.length;

Exception

Parameter Description
NullPointerException if either first or second is null

Return

a concatenated array

Declaration

public static double[] concat(double[] first, double[] second) 

Method Source Code

//package com.java2s;
/* ---------------------------------------------------------------------
 * Numenta Platform for Intelligent Computing (NuPIC)
 * Copyright (C) 2014, Numenta, Inc.  Unless you have an agreement
 * with Numenta, Inc., for a separate license for this software code, the
 * following terms and conditions apply:
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero Public License version 3 as
 * published by the Free Software Foundation.
 *
 * 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 Affero Public License for more details.
 *
 * You should have received a copy of the GNU Affero Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 *
 * http://numenta.org/licenses///from w  w  w  . ja v a 2  s.  c o m
 * ---------------------------------------------------------------------
 */

import java.util.Arrays;

public class Main {
    /**
     * Returns a new array of size first.length + second.length, with the
     * contents of the first array loaded into the returned array starting
     * at the zero'th index, and the contents of the second array appended
     * to the returned array beginning with index first.length.
     * 
     * This method is fail fast, meaning that it depends on the two arrays
     * being non-null, and if not, an exception is thrown.
     *  
     * @param first     the data to load starting at index 0
     * @param second    the data to load starting at index first.length;
     * @return  a concatenated array
     * @throws NullPointerException if either first or second is null
     */
    public static double[] concat(double[] first, double[] second) {
        double[] retVal = Arrays.copyOf(first, first.length + second.length);
        for (int i = first.length, j = 0; i < retVal.length; i++, j++) {
            retVal[i] = second[j];
        }
        return retVal;
    }
}

Related

  1. concat(boolean[]... arys)
  2. concat(byte[] a, byte[]... b)
  3. concat(byte[] first, byte[] second)
  4. concat(byte[] first, byte[] second)
  5. concat(byte[]... arrays)
  6. concat(final T[] elements, final T... elementsToAppend)
  7. concat(final T[] first, final T[] second)
  8. concat(float[] A, float[] B)
  9. concat(int[] first, int[] second)