Java Array to String arrayToString(Object array)

Here you can find the source of arrayToString(Object array)

Description

Convenience method.

License

Open Source License

Declaration

public static String arrayToString(Object array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w ww  . j ava  2s . c o  m
     * Convenience method.  Just casts the given object to Object[]
     * and calls the other version of this method.
     */
    public static String arrayToString(Object array) {
        if (array == null)
            return "null";
        else
            return arrayToString((Object[]) array);
    }

    /**
     * Prints each object in the array with commas between them.
     * Nulls will print as "null".  A null array will cause NPE.
     */
    public static String arrayToString(Object[] array) {
        StringBuffer outputString = new StringBuffer(100);
        for (int i = 0, n = array.length; i < n; i++) {
            if (i > 0)
                outputString.append(", ");
            outputString.append(array[i]);
        }
        return outputString.toString();
    }
}

Related

  1. arrayToString(int[] c, String separator)
  2. arrayToString(int[] s)
  3. arrayToString(int[] subset)
  4. arrayToString(int[][] array)
  5. arrayToString(Object arbitraryArray)
  6. arrayToString(Object array)
  7. arrayToString(Object array)
  8. arrayToString(Object obj)
  9. arrayToString(Object obj[])