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(float[] 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(float[][] array)
array To String
StringBuilder out = new StringBuilder();
for (int i = 0; i < array.length; i++) {
    for (int j = 0; j < array[0].length; j++) {
        out.append(array[i][j]).append(" ");
    out.append("\n");
return out.toString();
...
StringarrayToString(int[] ar)
array To String
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0; i < ar.length; i++) {
    sb.append(ar[i]);
    if (i + 1 < ar.length)
        sb.append(", ");
sb.append("]");
...
StringarrayToString(int[] arr)
array To String
if (arr == null || arr.length == 0) {
    return "";
String str = "[";
for (int i = 0; i < arr.length - 1; i++) {
    str += arr[i] + ",";
str += arr[arr.length - 1] + "]";
...
StringarrayToString(int[] arr)
Convert an array of double that contains accuracy/completeness/correctness into a string (from the 1st..6th elements)
String result = "[" + arr[0];
for (int i = 1; i < arr.length; i++)
    result += (";" + arr[i]);
result += "]";
return result;
StringarrayToString(int[] arr)
array To String
System.out.println(arr.length);
String s = "[";
for (int x = 0; x < arr.length; x++) {
    s += arr[x];
    if (x != arr.length - 1) {
        s += ", ";
s += "]";
return s;
StringarrayToString(int[] array)
Convenience method for creating a String from an array.
return Arrays.toString(array).replace('[', ' ').replace(']', ' ').replace(',', ' ');
StringarrayToString(int[] array)
array To String
StringBuilder output = new StringBuilder();
for (int i = 0; i < array.length - 1; i++) {
    output.append(String.format("%d\t", array[i]));
output.append(String.format("%d", array[array.length - 1]));
return output.toString();
StringarrayToString(int[] array)
Use only for testing.
StringBuilder buf = new StringBuilder();
buf.append("[");
for (int i = 0; i < array.length; i++) {
    if (i > 0) {
        buf.append(" ");
    buf.append(array[i]);
buf.append("]");
return buf.toString();
StringarrayToString(int[] array)
Convenience method for creating a String from an array.
return Arrays.toString(array).replace('[', ' ').replace(']', ' ').replace(',', ' ');