Java Primitive Type Create toPrimitive(Byte[] byteArray)

Here you can find the source of toPrimitive(Byte[] byteArray)

Description

Converts an array of object Bytes to primitives handling null .

License

Open Source License

Parameter

Parameter Description
byteArray a Byte array, may be null.

Return

a byte array, null if null array input.

Declaration

public static byte[] toPrimitive(Byte[] byteArray) 

Method Source Code

//package com.java2s;
/**/*from w ww .j ava2s  . c om*/
 * Copyright (c) 2011-2014 INRIA.
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * This program 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 Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 **/

public class Main {
    /**
     * Converts an array of object Bytes to primitives handling {@code null}.
     * 
     * This method returns {@code null} for a {@code null} input array.
     * 
     * @param byteArray
     *            a Byte array, may be null.
     * 
     * @return a byte array, null if null array input.
     */
    public static byte[] toPrimitive(Byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }

        byte[] unbox = new byte[byteArray.length];
        for (int i = 0; i < unbox.length; i++) {
            unbox[i] = byteArray[i];
        }
        return unbox;
    }
}

Related

  1. toPrimitive(Boolean b)
  2. toPrimitive(Boolean[] array)
  3. toPrimitive(Byte[] bytes)
  4. toPrimitive(Byte[] objectArray)
  5. toPrimitive(Character value)
  6. toPrimitive(Character[] in)