Java Array Print print(Object[] array)

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

Description

print

License

Open Source License

Declaration

public static String print(Object[] array) 

Method Source Code


//package com.java2s;
/* Copyright 2012, 2013 Unconventional Thinking
 *
 * This file is part of Hierarchy./*w  w  w.  ja v a2  s  . co  m*/
 *
 * Hierarchy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * Hierarchy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Hierarchy.  
 * If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.*;

public class Main {
    public static String print(List list) {
        return print(list, ", ");
    }

    public static String print(List list, String separator) {

        StringBuilder stringBuilder = new StringBuilder();

        if (list != null) {
            boolean isFirstItem = true;
            for (Object item : list) {
                if (!isFirstItem) {
                    stringBuilder.append(separator);
                }

                stringBuilder.append(item.toString());

                isFirstItem = false;
            }

        } else {
            return "";
        }

        return stringBuilder.toString();

    }

    public static String print(Object[] array) {
        return print(array, ", ");
    }

    public static String print(Object[] array, String separator) {

        StringBuilder stringBuilder = new StringBuilder();

        if (array != null) {
            boolean isFirstItem = true;
            for (Object item : array) {
                if (!isFirstItem) {
                    stringBuilder.append(separator);
                }

                stringBuilder.append(item.toString());

                isFirstItem = false;
            }

        } else {
            return "";
        }

        return stringBuilder.toString();

    }
}

Related

  1. formatStringForPrettyPrintingRelatedValues(double[] values, int minDigits)
  2. prettyPrint(double[][] gammas, double[][] thetas, double[][] zprobs)
  3. print(Object[] array)
  4. print(String[] files)
  5. print1DIntArray(int[] array)
  6. printArray(boolean[] array)