Java Array Concatenate concatArrays(final char[] first, final char[]... rest)

Here you can find the source of concatArrays(final char[] first, final char[]... rest)

Description

Concatenates multiple character arrays together.

License

Open Source License

Parameter

Parameter Description
first array to concatenate. Cannot be null.
rest of the arrays to concatenate. May be null.

Return

array containing the concatenation of all parameters

Declaration

public static char[] concatArrays(final char[] first, final char[]... rest) 

Method Source Code


//package com.java2s;
/* See LICENSE for licensing and NOTICE for copyright. */

import java.util.Arrays;

public class Main {
    /**/*from  w  w w.  j  av a2s  . com*/
     * Concatenates multiple character arrays together.
     *
     * @param  first  array to concatenate. Cannot be null.
     * @param  rest  of the arrays to concatenate. May be null.
     *
     * @return  array containing the concatenation of all parameters
     */
    public static char[] concatArrays(final char[] first, final char[]... rest) {
        int totalLength = first.length;
        for (char[] array : rest) {
            if (array != null) {
                totalLength += array.length;
            }
        }

        final char[] result = Arrays.copyOf(first, totalLength);

        int offset = first.length;
        for (char[] array : rest) {
            if (array != null) {
                System.arraycopy(array, 0, result, offset, array.length);
                offset += array.length;
            }
        }
        return result;
    }
}

Related

  1. concatArrays(byte[]... arrays)
  2. concatArrays(byte[]... byaArrays)
  3. concatArrays(byte[][] arrays)
  4. concatArrays(double[] d1, double[] d2)
  5. concatArrays(final byte[] arr1, final byte[] arr2)
  6. concatArrays(Object[] ar1, Object[] ar2)
  7. concatArrays(short[] arr1, short[] arr2)
  8. concatArrays(String[] A, String[] B)
  9. concatArrays(String[] array, String[] arrayToBeConcat)