Java Collection to String collectionToString(Collection col)

Here you can find the source of collectionToString(Collection col)

Description

Prints each object in the collection with commas between them.

License

Open Source License

Declaration

public static String collectionToString(Collection col) 

Method Source Code

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

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**/* w  w w. jav  a2  s .c om*/
     * Prints each object in the collection with commas between them.
     * Nulls will print as "null".  A null collection will cause NPE.
     */
    public static String collectionToString(Collection col) {
        StringBuffer outputString = new StringBuffer(100);
        boolean firstItem = true;
        Iterator it = col.iterator();
        while (it.hasNext()) {
            if (!firstItem)
                outputString.append(", ");
            outputString.append(it.next());
            firstItem = false;
        }
        return outputString.toString();
    }
}

Related

  1. collectionToString( Collection collection)
  2. collectionToString(@SuppressWarnings("rawtypes") Collection coll)
  3. collectionToString(Collection c)
  4. collectionToString(Collection c, String delim)
  5. collectionToString(Collection c, String spilt)
  6. collectionToString(Collection coll)
  7. collectionToString(Collection collection, String delim)
  8. collectionToString(Collection list, String split)
  9. collectionToString(Collection set)