Java Array Deep to String deepToString(Object[] array)

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

Description

Simple method to walk an array and call toString() on each of the entries.

License

Open Source License

Parameter

Parameter Description
array the array

Return

the comma-separated string representation of the the array

Declaration

public static String deepToString(Object[] array) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from  w ww  .  jav a2 s  .c om*/
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Simple method to walk an array and call <code>toString()</code> on each of the entries. Does not descend into sub-collections.
     * @param array the array
     * @return the comma-separated string representation of the the array
     * @since 1.0.3
     */
    public static String deepToString(Object[] array) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < array.length; i++) {
            buffer.append(array[i].toString());
            if (i < array.length - 1) {
                buffer.append(',');
            }
        }
        return buffer.toString();
    }
}

Related

  1. deepToString(double[][] array)
  2. deepToString(int[] values)