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

StringarrayToString(Object[] array, String separator)
array To String
if (array == null || array.length == 0) {
    return "";
StringBuffer s = new StringBuffer(32 * array.length);
s.append(array[0]);
for (int i = 1; i < array.length; i++) {
    s.append(separator).append(array[i]);
return s.toString();
StringarrayToString(Object[] array, String split)
array To String
if (array == null) {
    return "";
} else {
    StringBuffer str = new StringBuffer("");
    for (int i = 0; i < array.length; ++i) {
        if (i != array.length - 1) {
            str.append(array[i].toString()).append(split);
        } else {
...
StringarrayToString(Object[] ary)
Converts an array of objects to a string, by concatenating them together and separated with comma.
if (ary == null || ary.length == 0)
    return "";
final StringBuffer sb = new StringBuffer(50);
for (int j = 0; j < ary.length; ++j) {
    if (j > 0)
        sb.append(',');
    if (ary[j] != null)
        sb.append(ary[j]);
...
StringarrayToString(Object[] list)
Returns string representation of array of objects.
if (list == null) {
    return null;
String res = "[ ";
for (int i = 0; i < list.length; ++i) {
    res += list[i] + " ";
res += "]";
...
StringarrayToString(Object[] objects)
array To String
boolean first = true;
StringBuilder sb = new StringBuilder();
for (Object object : objects) {
    if (first) {
        first = false;
    } else {
        sb.append(", ");
    sb.append(object.toString());
return sb.toString();
StringarrayToString(Object[] objects)
Converts an array of objects to a string which can be inserted into log messages.
if (objects == null)
    return "null";
StringBuffer buffer = new StringBuffer("{");
for (int i = 0; i < objects.length; i++) {
    if (i > 0)
        buffer.append(", ");
    buffer.append(objects[i]);
buffer.append("}");
return buffer.toString();
StringarrayToString(Object[] objects)
array To String
List<Object> x = newList();
x.addAll(Arrays.asList(objects));
return x.toString();
StringarrayToString(Object[] objects)
Pretty print an array of objects as [ object1.toString,() object2.toString(), ...
int num = objects.length;
if (num == 0) {
    return "[]";
} else {
    StringBuffer buffer = new StringBuffer("[ ");
    for (int i = 0; i < num; i++) {
        if (i > 0) {
            buffer.append(", ");
...
StringarrayToString(Object[] objs)
Returns a String containing all the objects
return arrayToString(objs, "");
StringarrayToString(Object[] objs)
array To String
StringBuffer buffer = new StringBuffer();
if (objs != null) {
    for (int i = 0; i < objs.length; i++) {
        if (buffer.length() > 0)
            buffer.append("\n");
        buffer.append(objs[i]);
return buffer.toString();