Java Utililty Methods Byte Array Create

List of utility methods to do Byte Array Create

Description

The list of methods to do Byte Array Create are organized into topic(s).

Method

byte[]toByteArray(byte b)
to Byte Array
byte[] array = new byte[1];
array[0] = b;
return array;
byte[]toByteArray(byte byteArray)
to Byte Array
return new byte[] { byteArray };
byte[]toByteArray(byte num)
to Byte Array
return new byte[] { num };
byte[]toByteArray(byte value)
to Byte Array
return new byte[] { value };
byte[]toByteArray(char c)
Converts an char to the corresponding byte[] array.
return toByteArray(c, false);
byte[]toByteArray(char[] charArray)
A utility method to convert from chars to bytes
if (charArray == null) {
    return null;
byte[] result = new byte[charArray.length];
for (int i = 0; i < charArray.length; i++) {
    result[i] = (byte) charArray[i];
return result;
...
byte[]toByteArray(char[] chars)
to Byte Array
byte[] bytes = new byte[chars.length];
for (int i = 0; i != bytes.length; i++) {
    bytes[i] = (byte) chars[i];
return bytes;
byte[]toByteArray(char[] chars)
Convert the given char array into a byte array.
byte[] result = new byte[chars.length];
for (int i = chars.length - 1; i >= 0; i--) {
    result[i] = (byte) chars[i];
return result;
byte[]toByteArray(char[] src)
to Byte Array
byte[] arr = new byte[src.length * 2];
for (int i = 0; i < src.length; i++) {
    char chr = src[i];
    arr[i * 2] = (byte) (0xff & (chr >> 8));
    arr[i * 2 + 1] = (byte) (0xff & (chr));
return arr;
byte[]toByteArray(CharSequence hexString)
Creates a byte array from a CharSequence (String, StringBuilder, etc.) containing only valid hexidecimal formatted characters.
if (hexString == null) {
    return null;
return toByteArray(hexString, 0, hexString.length());