Java Array Clone cloneByteArray(byte[] b)

Here you can find the source of cloneByteArray(byte[] b)

Description

Create a new byte array and copy all the data.

License

Open Source License

Parameter

Parameter Description
b the byte array (may not be null)

Return

a new byte array

Declaration

public static byte[] cloneByteArray(byte[] b) 

Method Source Code

//package com.java2s;
/*//w  w  w. j  ava2s. c  om
 * Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0
 * (http://h2database.com/html/license.html). Initial Developer: H2 Group
 */

public class Main {
    /**
     * Create a new byte array and copy all the data. If the size of the byte array is zero, the same array is returned.
     * 
     * @param b
     *            the byte array (may not be null)
     * @return a new byte array
     */
    public static byte[] cloneByteArray(byte[] b) {

        if (b == null) {
            return null;
        }
        int len = b.length;
        if (len == 0) {
            return b;
        }
        byte[] copy = new byte[len];
        System.arraycopy(b, 0, copy, 0, len);
        return copy;
    }
}

Related

  1. cloneArray(final String[] inputArray)
  2. cloneArray(int[] array)
  3. clonearray(int[] clonethis)
  4. cloneArray(int[] src)
  5. cloneArray(String[] orArray, int from)
  6. cloneBytes(byte[] buffer)
  7. cloneCharArray(char[] chars)
  8. cloneDoubleMatrix(double[][] src)
  9. cloneIntArray(int array[])