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

StringbytesToString(byte[] bytes)
bytes To String
String result = "[";
for (int i = 0; i < bytes.length; i++) {
    result += bytes[i];
    if (i < bytes.length - 1) {
        result += ",";
return result + "]";
...
StringbytesToString(byte[] bytes)
Stores the bytes of the byte array in a hexstring
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
    String str = Long.toString(b & 0xff, 16);
    sb.append(str.length() < 2 ? "0" + str : str);
return sb.toString();
StringbytesToString(byte[] bytes)
bytes To String
if (bytes == null) {
    return null;
return new String(bytes);
StringbytesToString(byte[] bytes)
bytes To String
int readBytes = bytes.length;
StringBuffer hexData = new StringBuffer();
for (int i = 0; i < readBytes; i++) {
    hexData.append(hexLookupTable[0xff & bytes[i]]);
return hexData.toString();
StringbytesToString(byte[] bytes)
bytes To String
StringBuffer sBuffer = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
    sBuffer.append(byteToString(bytes[i]));
    if (i != bytes.length - 1)
        sBuffer.append("-");
return sBuffer.toString();
StringbytesToString(byte[] bytes)
bytes To String
StringBuffer encryptedUserID = new StringBuffer();
for (int i = 0; i < bytes.length; ++i) {
    String hex = Integer.toHexString(0xff & bytes[i]);
    if (hex.length() == 1) {
        encryptedUserID.append('0');
    encryptedUserID.append(hex);
return encryptedUserID.toString();
StringbytesToString(byte[] bytes)
bytes To String
return bytesToString(bytes, false);
StringbytesToString(byte[] bytes, int offs, int len)
bytes To String
StringBuilder b = new StringBuilder(len * 2);
int h, l;
for (int i = 0; i < len; i++) {
    h = bytes[i + offs] & 0xff;
    l = h & 0x0f;
    h >>= 4;
    if (h < 10) {
        b.append('0' + h);
...
StringbytesToString(byte[] bytes, int startIndex)
Given a byte array, restore a String out of it.
int len = (int) (bytes[startIndex++]) & 0xff;
return new String(bytes, startIndex, len);
StringbytesToString(byte[] bytes, String encoding)
bytes To String
if (bytes == null) {
    throw new IllegalArgumentException("bytes may not be null in string conversion");
if (bytes.length == 0) {
    return null;
try {
    return new String(bytes, encoding);
...