Java Array Print printArray(String arrayLabel, Object[] array)

Here you can find the source of printArray(String arrayLabel, Object[] array)

Description

Debugging support -- Print contents of an array.

License

Open Source License

Parameter

Parameter Description
arrayLabel Label for array.
array The array to print. <p> N.B. This method assumes the array values have toString() methods. </p>

Declaration


public static void printArray(String arrayLabel, Object[] array) 

Method Source Code

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

public class Main {
    /** Debugging support -- Print contents of an array.
     *// ww  w .j  av  a  2  s .  c o m
     *   @param   arrayLabel      Label for array.
     *
     *   @param   array         The array to print.
     *
     *   <p>
     *   N.B.  This method assumes the array values have toString() methods.
     *   </p>
     */

    public static void printArray(String arrayLabel, Object[] array) {
        if (array == null) {
            System.out.println(arrayLabel + " is null.");
        } else if (array.length == 0) {
            System.out.println(arrayLabel + " is empty.");
        } else {
            System.out.println(arrayLabel);

            for (int i = 0; i < array.length; i++) {
                Object value = array[i];

                if (value == null) {
                    System.out.println(i + ": null");
                } else {
                    System.out.println(i + ": " + value.toString());
                }
            }
        }
    }
}

Related

  1. printArray(Object[] array)
  2. printArray(Object[] array)
  3. printArray(Object[] cells)
  4. printArray(Object[] o)
  5. printArray(Object[] strArray, String split)
  6. printArray(String[] arr, char separator)
  7. printArray(String[] s)
  8. printArray(String[] s)
  9. printArray(T[] arr)