Java Array to String array2String(Object[] a, int size)

Here you can find the source of array2String(Object[] a, int size)

Description

array String

License

Open Source License

Declaration

public static String array2String(Object[] a, int size) 

Method Source Code

//package com.java2s;
/*//from   w w  w . j  a  va  2s  .c  o  m
 * Copyright (c) 2016. Pun.W <punyj177 at gmail dot com>
 *
 * Everyone is permitted to copy and distribute verbatim or modified copies of this license
 * document, and changing it is allowed as long as the name is changed.
 *
 * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING,
 * DISTRIBUTION AND MODIFICATION
 *
 * 0. You just DO WHAT THE FUCK YOU WANT TO.
 */

public class Main {
    public static String array2String(Object[] a, int size) {
        if (a == null)
            return "null";

        int iMax = size - 1;
        if (iMax == -1)
            return "[]";

        StringBuilder b = new StringBuilder();
        b.append('[');
        for (int i = 0;; i++) {
            b.append(String.valueOf(a[i]));
            if (i == iMax)
                return b.append(']').toString();
            b.append(", ");
        }
    }
}

Related

  1. array2string(final T[] array, final int top)
  2. array2string(int[] _a)
  3. array2String(int[] paramArrayOfInt)
  4. array2String(long[] array)
  5. array2String(long[] array)
  6. array2string(Object[] array)
  7. array2String(Object[] objs)
  8. array2String(String[] array)
  9. array2String(String[] array)