Java Array to String arrayToString(final Object[] a)

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

Description

Converts the given array of Objects into a String.

License

Open Source License

Declaration

public static String arrayToString(final Object[] a) 

Method Source Code

//package com.java2s;
/*/*  w ww.j a  v a  2 s.  c o  m*/
 * #%L
 * VisBio application for visualization of multidimensional biological
 * image data.
 * %%
 * Copyright (C) 2002 - 2014 Board of Regents of the University of
 * Wisconsin-Madison.
 * %%
 * This program 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 2 of the
 * License, or (at your option) any later version.
 * 
 * This program 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 this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-2.0.html>.
 * #L%
 */

public class Main {
    /** Converts the given array of Objects into a String. */
    public static String arrayToString(final Object[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0].toString());
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i].toString());
        }
        return sb.toString();
    }

    /** Converts the given array of booleans into a String. */
    public static String arrayToString(final boolean[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }

    /** Converts the given array of bytes into a String. */
    public static String arrayToString(final byte[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }

    /** Converts the given array of chars into a String. */
    public static String arrayToString(final char[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }

    /** Converts the given array of doubles into a String. */
    public static String arrayToString(final double[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }

    /** Converts the given array of floats into a String. */
    public static String arrayToString(final float[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }

    /** Converts the given array of ints into a String. */
    public static String arrayToString(final int[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }

    /** Converts the given array of longs into a String. */
    public static String arrayToString(final long[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }

    /** Converts the given array of shorts into a String. */
    public static String arrayToString(final short[] a) {
        if (a == null)
            return "null";
        if (a.length == 0)
            return "";
        final StringBuffer sb = new StringBuffer();
        sb.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            sb.append(",");
            sb.append(a[i]);
        }
        return sb.toString();
    }
}

Related

  1. arrayToString(double[] v)
  2. arrayToString(double[] xs)
  3. arrayToString(final byte[] array)
  4. arrayToString(final byte[] array, final int start, final int length)
  5. arrayToString(final float[] array)
  6. arrayToString(final Object[] arr)
  7. arrayToString(final Object[] array)
  8. arrayToString(final Object[] array)
  9. arrayToString(final String[] args)