Java Collection to String collectionToString(final String separator, final Collection coll)

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

Description

collection To String

License

BSD License

Declaration

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

Method Source Code

//package com.java2s;
/*/*from   w  w w .j  a  v  a2s  . c om*/
 * (c) 2009-2012 Julien Rialland, and the jFastCGI project developers.
 * Released under BSD License, see LICENSE_JRIALLAND.txt
 */

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static String collectionToString(final String separator, final Collection<?> coll) {
        final StringBuffer buf = new StringBuffer();
        final Iterator<?> it = coll.iterator();
        while (it.hasNext()) {

            final Object item = it.next();
            if (item == null) {
                buf.append("null");
            } else {
                buf.append(item.toString());
            }

            if (it.hasNext()) {
                buf.append(separator);
            }
        }
        return buf.toString();
    }
}

Related

  1. collectionToString(final Collection collection, final String recordSeparator)
  2. collectionToString(final Collection aCol, final String aSepLines)
  3. collectionToString(final Collection c)
  4. collectionToString(final Collection collection, final String separator)
  5. collectionToString(final Collection elements, final String separator)
  6. collectionToString(Iterable c)
  7. collectionToString(Object[] objects)
  8. collectionToString(String prefix, Collection list)
  9. collectionToStringArray(Collection holder)