Java Array to String arrayToString(Object[] objects)

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

Description

Pretty print an array of objects as [ object1.toString,() object2.toString(), ...

License

Open Source License

Declaration

public static String arrayToString(Object[] objects) 

Method Source Code

//package com.java2s;
/*// ww  w .  j a  va 2s.  c o m
 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
 * 
 * This software is open source. 
 * See the bottom of this file for the licence.
 * 
 * $Id: StringUtils.java,v 1.1.1.1 2001/05/22 08:13:01 jstrachan Exp $
 */

public class Main {
    /** Pretty print an array of objects as [ object1.toString,() object2.toString(), ... ]
      */
    public static String arrayToString(Object[] objects) {
        int num = objects.length;
        if (num == 0) {
            return "[]";
        } else {
            StringBuffer buffer = new StringBuffer("[ ");
            for (int i = 0; i < num; i++) {
                if (i > 0) {
                    buffer.append(", ");
                }
                Object object = objects[i];
                if (object != null) {
                    buffer.append(object.toString());
                } else {
                    buffer.append("null");
                }

            }
            buffer.append(" ]");
            return buffer.toString();
        }
    }
}

Related

  1. arrayToString(Object[] ary)
  2. arrayToString(Object[] list)
  3. arrayToString(Object[] objects)
  4. arrayToString(Object[] objects)
  5. arrayToString(Object[] objects)
  6. arrayToString(Object[] objs)
  7. arrayToString(Object[] objs)
  8. arrayToString(Object[] objs, boolean stripPackageNames)
  9. arrayToString(Object[] objs, String separator)