Java Array to String arrayToString(T[] array)

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

Description

array To String

License

Open Source License

Declaration

public static <T> String arrayToString(T[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static <T> String arrayToString(T[] array) {
        return arrayToString(array, ",", "", "");
    }//from ww  w.  j a  va2s.  c o m

    public static <T> String arrayToString(T[] array, String connectSymbol) {
        return arrayToString(array, connectSymbol, "", "");
    }

    public static <T> String arrayToString(T[] array, String leading, String trailing) {
        return arrayToString(array, ",", leading, trailing);
    }

    public static <T> String arrayToString(T[] array, String connectSymbol, String leading, String trailing) {
        connectSymbol = (connectSymbol == null ? "" : connectSymbol);
        leading = (leading == null ? "" : leading);
        trailing = (trailing == null ? "" : trailing);
        int len = array.length;
        if (len == 0)
            return "";
        StringBuffer buf = new StringBuffer(len * 12 + leading.length() + trailing.length());
        for (int i = 0; i < len - 1; i++) {
            buf.append(leading).append(array[i].toString()).append(trailing).append(connectSymbol);
        }
        return buf.append(leading).append(array[len - 1].toString()).append(trailing).toString();
    }
}

Related

  1. arrayToString(T[] ar)
  2. arrayToString(T[] array)
  3. arrayToString(T[] array)
  4. arrayToString(T[] array)
  5. arrayToString(T[] array)
  6. arrayToString(T[] array)
  7. arrayToString(T[] array, CharSequence start, CharSequence end)
  8. arrayToString(T[] items, String delimiter)
  9. arrayToString2D(String title, String innerTitle, double[][] vect)