Java Array to String arrayToString(Object[] array)

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

Description

array To String

License

Apache License

Declaration

public static String arrayToString(Object[] array) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String arrayToString(Object[] array) {
        if (array == null) {
            return "";
        }//from w w w  . j a  va  2s.  c o  m
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (Object obj : array) {
            sb.append(obj == null ? "" : obj.toString());
            sb.append(",");
        }
        if (sb.indexOf(",") > -1) {
            sb.deleteCharAt(sb.lastIndexOf(","));
        }
        sb.append("]");
        return sb.toString();
    }

    public static String arrayToString(long[] array) {
        if (array == null) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (long obj : array) {
            sb.append(obj);
            sb.append(",");
        }
        if (sb.indexOf(",") > -1) {
            sb.deleteCharAt(sb.lastIndexOf(","));
        }
        sb.append("]");
        return sb.toString();
    }
}

Related

  1. arrayToString(Object[] array)
  2. arrayToString(Object[] array)
  3. arrayToString(Object[] array)
  4. arrayToString(Object[] array)
  5. arrayToString(Object[] array)
  6. arrayToString(Object[] array)
  7. arrayToString(Object[] array)
  8. ArrayToString(Object[] array, String conv)
  9. arrayToString(Object[] array, String delim, int maxValues, boolean useBrackets)