Java Array Print printArray(Object[] arr)

Here you can find the source of printArray(Object[] arr)

Description

Prints an array of stuff, with the notation {x1,x2,x3...,xn}, or "" if the array is empty.

License

Open Source License

Parameter

Parameter Description
arr The array of objects.

Return

The string representation of the passed array as {x1,x2,x3...,xn}, or "" is array empty.

Declaration

public static String printArray(Object[] arr) 

Method Source Code

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

public class Main {
    /**/*from  w  w w .j  a  v  a2  s  . c  om*/
     * Prints an array of stuff, with the notation {x1,x2,x3...,xn}, or "" if the array is empty.
     * Each passed object will be printed according to its arr[i].toString() output.
     * @param arr The array of objects.
     * @return The string representation of the passed array as {x1,x2,x3...,xn}, or "" is array empty.
     */
    public static String printArray(Object[] arr) {
        String toPrint = "";

        if (arr.length > 0) {
            toPrint = "{";
            for (int i = 0; i < arr.length; i++) {
                toPrint += arr[i].toString();
                if (i < arr.length - 1)
                    toPrint += ",";
            }
            toPrint += "}";
        }
        return toPrint;
    }
}

Related

  1. printArray(int[] array)
  2. printArray(int[] array)
  3. printArray(int[] array, int start, int end)
  4. printArray(int[] nums)
  5. printArray(Object a[])
  6. printArray(Object[] array)
  7. printArray(Object[] array)
  8. printArray(Object[] cells)
  9. printArray(Object[] o)