Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * 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();
    }
}