Java Array Clone cloneCharArray(char[] chars)

Here you can find the source of cloneCharArray(char[] chars)

Description

Create a new char array and copy all the data.

License

Open Source License

Parameter

Parameter Description
chars the char array (may be null)

Return

a new char array

Declaration

public static char[] cloneCharArray(char[] chars) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  ww w  . ja v a2 s  .  co m
     * Create a new char array and copy all the data. If the size of the byte
     * array is zero, the same array is returned.
     *
     * @param chars the char array (may be null)
     * @return a new char array
     */
    public static char[] cloneCharArray(char[] chars) {
        if (chars == null) {
            return null;
        }
        int len = chars.length;
        if (len == 0) {
            return chars;
        }
        char[] copy = new char[len];
        System.arraycopy(chars, 0, copy, 0, len);
        return copy;
    }
}

Related

  1. clonearray(int[] clonethis)
  2. cloneArray(int[] src)
  3. cloneArray(String[] orArray, int from)
  4. cloneByteArray(byte[] b)
  5. cloneBytes(byte[] buffer)
  6. cloneDoubleMatrix(double[][] src)
  7. cloneIntArray(int array[])
  8. cloneLong(long[] array)
  9. cloneNonNullArray(double[] array)