Android Byte 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 av  a  2s  . c  o  m
 * Copyright 2004-2008 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. clone(byte[] array)