Java Array to String arrayToString(Object[] array)

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

Description

Convert array contents to string.

License

Open Source License

Parameter

Parameter Description
array The array to convert to a string.

Return

Array entries as a string.

N.B. This method assumes the array values have toString() methods.

Declaration


public static String arrayToString(Object[] array) 

Method Source Code

//package com.java2s;
/*   Please see the license information at the end of this file. */

public class Main {
    /**//from   w  w w  .  j a v a 2  s  .  c o m
     * Convert array contents to string.
     * 
     * @param array
     *            The array to convert to a string.
     * 
     * @return Array entries as a string.
     * 
     *         <p>
     *         N.B. This method assumes the array values have toString()
     *         methods.
     *         </p>
     */

    public static String arrayToString(Object[] array) {
        String result = "";

        if ((array != null) && (array.length > 0)) {
            for (int i = 0; i < array.length; i++) {
                Object value = array[i];

                if (i > 0)
                    result = result + ", ";

                if (value == null) {
                    result = result + "null";
                } else {
                    result = result + value.toString();
                }
            }
        }

        return result;
    }
}

Related

  1. arrayToString(Object[] arr)
  2. arrayToString(Object[] arr)
  3. arrayToString(Object[] arr)
  4. arrayToString(Object[] arr)
  5. arrayToString(Object[] arr, String split)
  6. arrayToString(Object[] array)
  7. arrayToString(Object[] array)
  8. arrayToString(Object[] array)
  9. arrayToString(Object[] array)