Java Array Concatenate concat(float[] A, float[] B)

Here you can find the source of concat(float[] A, float[] B)

Description

Concatenates two arrays into one

License

Open Source License

Parameter

Parameter Description
A first array
B second array

Return

concatenated array

Declaration

public static float[] concat(float[] A, float[] B) 

Method Source Code

//package com.java2s;
/*//from www .  j a va2 s .c o m
 * Copyright (c) 2008-2013 Maksim Khadkevich and Fondazione Bruno Kessler.
 *
 * This file is part of MART.
 * MART is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2, as published
 * by the Free Software Foundation.
 *
 * MART 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 MART; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.util.List;

public class Main {
    /**
     * Concatenates two arrays into one
     *
     * @param A first array
     * @param B second array
     * @return concatenated array
     */
    public static float[] concat(float[] A, float[] B) {
        float[] C = new float[A.length + B.length];
        System.arraycopy(A, 0, C, 0, A.length);
        System.arraycopy(B, 0, C, A.length, B.length);
        return C;
    }

    public static short[] concat(short[] A, short[] B) {
        short[] C = new short[A.length + B.length];
        System.arraycopy(A, 0, C, 0, A.length);
        System.arraycopy(B, 0, C, A.length, B.length);
        return C;
    }

    public static int[] concat(int[] A, int[] B) {
        int[] C = new int[A.length + B.length];
        System.arraycopy(A, 0, C, 0, A.length);
        System.arraycopy(B, 0, C, A.length, B.length);
        return C;
    }

    /**
     * Concatenates two arrays into one
     *
     * @param A first array
     * @param B second array
     * @return concatenated array
     */
    public static byte[] concat(byte[] A, byte[] B) {
        byte[] C = new byte[A.length + B.length];
        System.arraycopy(A, 0, C, 0, A.length);
        System.arraycopy(B, 0, C, A.length, B.length);
        return C;
    }

    /**
     * Concatenates 2d arrays
     *
     * @return
     */
    public static float[] concat(List<float[]> inputs) {
        int numberOfFrames = 0;
        for (float[] anInput : inputs) {
            numberOfFrames += anInput.length;
        }
        float[] output = new float[numberOfFrames];
        int pointer = 0;
        for (float[] anInput : inputs) {
            for (float anAnInput : anInput) {
                output[pointer++] = anAnInput;
            }
        }
        return output;
    }
}

Related

  1. concat(byte[] first, byte[] second)
  2. concat(byte[]... arrays)
  3. concat(double[] first, double[] second)
  4. concat(final T[] elements, final T... elementsToAppend)
  5. concat(final T[] first, final T[] second)
  6. concat(int[] first, int[] second)
  7. concat(int[]... arrays)
  8. concat(Object[] array)
  9. concat(Object[] first, Object second)