Java Utililty Methods Array to String

List of utility methods to do Array to String

Description

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

Method

StringarrayToRLEString(short[] a)
Construct a string representing a short array.
StringBuffer buffer = new StringBuffer();
buffer.append((char) (a.length >> 16));
buffer.append((char) a.length);
short runValue = a[0];
int runLength = 1;
for (int i = 1; i < a.length; ++i) {
    short s = a[i];
    if (s == runValue && runLength < 0xFFFF)
...
StringarrayToStr(Object[] arr, char split)
e.g: String[] result={"TYHR0001","TYHR0002"}; split=","; return: str="TYHR0001,TYHR0002";
if (arr == null || arr.length == 0) {
    return null;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
    if (i > 0) {
        sb.append(split);
    sb.append(arr[i]);
return sb.toString();
StringarrayToStr(Object[] arr, char split)
e.g: String[] result={"TYHR0001","TYHR0002"}; split=","; return: str="TYHR0001,TYHR0002";
if (arr == null || arr.length == 0) {
    return null;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
    if (i > 0) {
        sb.append(split);
    sb.append(arr[i]);
return sb.toString();
StringarrayToStr(String[] o)
array To Str
String str = "";
if (o == null || o.length < 1)
    return "";
for (String s : o)
    str += s + ",";
return str.substring(0, str.length() - 1);
StringArrayToStr(String[] strArr, String seperatedBy)
Array To Str
String str = "";
for (int i = 0; i < strArr.length; i++) {
    str += strArr[i] + seperatedBy;
return str;
StringarrayToStr(String[] strArray)
array To Str
StringBuffer strBuffer = new StringBuffer();
for (String str : strArray) {
    strBuffer.append(strBuffer.length() > 0 ? "," : "").append(str);
return strBuffer.toString();
StringarrayToString(byte[] arg)
array To String
StringBuffer s = new StringBuffer(arg.toString());
s.append(" : ");
for (int i = 0; i < arg.length; ++i) {
    s.append(arg[i]);
    s.append(" ");
return s.toString();
StringarrayToString(byte[] array)
Pretty-prints a byte array
StringBuilder result = new StringBuilder("[");
for (int index = 0; index < array.length - 1; ++index) {
    result.append(array[index]).append(",");
if (array.length > 0) {
    result.append(array[array.length - 1]);
result.append("]");
...
StringarrayToString(byte[] bytes)
array To String
StringBuilder result = new StringBuilder(bytes.length * 4);
int i = 0;
while (i < bytes.length) {
    int value = bytes[i] & 0xFF;
    result.append(hexChar(value / 16));
    result.append(hexChar(value % 16));
    i++;
    if (i % BYTES_PER_LINE == 0) {
...
StringarrayToString(byte[] source, int index, short size)
array To String
byte[] array = new byte[size * 2];
for (int i = index; i <= (size * 2) + 2; i++) {
    array[i - index] = source[i];
String string = "UNDEFINED";
try {
    string = new String(array, 0, array.length, "UTF-16BE");
} catch (UnsupportedEncodingException e) {
...