Java Utililty Methods Byte Array to String

List of utility methods to do Byte Array to String

Description

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

Method

Stringbytes2string(byte[] src)
bytesstring
StringBuilder sb = new StringBuilder();
if (src == null || src.length <= 0) {
    return null;
for (int i = 0; i < src.length; i++) {
    int v = src[i] & 0xFF;
    String hv = Integer.toHexString(v);
    if (hv.length() < 2) {
...
Stringbytes2string(byte[] src)
bytesstring
char[] hexChars = new char[src.length * 2];
for (int j = 0; j < src.length; j++) {
    int v = src[j] & 0xFF;
    hexChars[j * 2] = HEX_ARRAY[v >>> 4];
    hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
return new String(hexChars);
StringbytesToStr(byte[] bytes)
bytes To Str
String result = "";
byte[] var3 = bytes;
int var4 = bytes.length;
for (int var5 = 0; var5 < var4; ++var5) {
    byte aByte = var3[var5];
    String temp = Integer.toHexString(aByte & 255);
    if (temp.length() == 1) {
        temp = "0" + temp;
...
StringbytesToStr(byte[] input)
bytes To Str
String res = "";
for (byte b : input) {
    res += byteToStr(b);
return res;
StringbytesToStrHex(byte[] bytes)
bytes To Str Hex
StringBuffer sb = new StringBuffer(bytes.length);
String sTemp;
for (int i = 0; i < bytes.length; i++) {
    sTemp = Integer.toHexString(0xFF & bytes[i]);
    if (sTemp.length() < 2)
        sb.append(0);
    sb.append(sTemp.toUpperCase());
return sb.toString();
StringbytesToString(byte... bytes)
bytes To String
StringBuilder builder = new StringBuilder();
for (byte aByte : bytes) {
    String binStr = Integer.toBinaryString(aByte);
    int length = binStr.length();
    if (length > 8) {
        builder.append(binStr.substring(length - 8)).append(" ");
    } else {
        builder.append(String.format("%08d", Integer.parseInt(binStr))).append(" ");
...
StringbytesToString(byte[] arr)
Byte array to string including the 0X notation
return bytesToString(arr, null);
StringbytesToString(byte[] arr, int pos)
Reads a string from a byte array.
checkBounds(arr, pos);
int charCount = bytesToInt(arr, pos);
String str = "";
for (int i = 0; i < charCount; i++) {
    str += bytesToChar(arr, pos + 4 + (i * 2));
return str;
StringbytesToString(byte[] b)
Produces a string prepresentation of the byte array.
StringBuffer sb;
sb = new StringBuffer();
sb.append("{ ");
for (int ii = 0; ii < b.length; ++ii) {
    if (ii > 0) {
        sb.append(", ");
    sb.append(b[ii]);
...
StringbytesToString(byte[] buffer, int index, int length)
This function converts the bytes in a byte array at the specified index to its corresponding string value.
return new String(buffer, index, length);