Java Collection to String collectionToString(Collection coll, String connectSymbol)

Here you can find the source of collectionToString(Collection coll, String connectSymbol)

Description

collection To String

License

Open Source License

Declaration

public static String collectionToString(Collection<?> coll, String connectSymbol) 

Method Source Code

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

import java.util.Collection;

public class Main {
    public static String collectionToString(Collection<?> coll, String connectSymbol) {
        return collectionToString(coll, connectSymbol, "", "");
    }/*from w  w w  .ja  v  a  2 s . co  m*/

    public static String collectionToString(Collection<?> coll, String connectSymbol, String leading,
            String trailing) {
        return arrayToString(coll.toArray(), connectSymbol, leading, trailing);
    }

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

    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. collectionToString(Collection c)
  2. collectionToString(Collection c)
  3. collectionToString(Collection c)
  4. collectionToString(Collection c)
  5. collectionToString(Collection c, String separator)
  6. collectionToString(Collection collection, String separator)
  7. collectionToString(Collection collection, String separator)
  8. collectionToString(Collection elements)
  9. collectionToString(Collection list)