Java Collection to String convertCollectionToCommaDelimitedString(Collection collection)

Here you can find the source of convertCollectionToCommaDelimitedString(Collection collection)

Description

convert Collection To Comma Delimited String

License

Open Source License

Declaration

public static String convertCollectionToCommaDelimitedString(Collection collection) 

Method Source Code


//package com.java2s;

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

public class Main {
    public static String convertCollectionToCommaDelimitedString(Collection collection) {
        StringBuffer sb = new StringBuffer();
        if (collection != null) {
            Iterator iter = collection.iterator();
            int count = 0;
            while (iter.hasNext()) {
                String item = (String) iter.next();
                if (count != 0) {
                    sb.append(", ");
                }/*from www  . j  a  va 2  s .  c o  m*/
                sb.append(item);
                count++;
            }
        }
        return sb.toString();
    }
}

Related

  1. collectionToStringList(Collection c)
  2. collectionToStringList(Collection c)
  3. collectionToStringList(Collection list, String delimiter)
  4. commaSeparatedList(Collection objects)
  5. commaSeparatedString(List list, boolean quoteStrings)
  6. convertCollectionToString( Collection strings, String separator)
  7. convertCollectionToString(Collection coll, String delimiter)
  8. convertEnumsToString(Collection> enums)
  9. convertListToString(Collection list)