Java Collection to String collectionToCSString(Collection col)

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

Description

Transform collection to comma split string.

License

Open Source License

Parameter

Parameter Description
E a parameter
col a parameter

Declaration

public static <E> String collectionToCSString(Collection<E> col) 

Method Source Code


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

import java.util.Collection;

public class Main {
    /**// ww w . j  av  a  2s. co  m
     * Transform collection to comma split string.
     *
     * @param <E>
     * @param col
     * @return
     */
    public static <E> String collectionToCSString(Collection<E> col) {
        if (col == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (E e : col) {
            sb.append(e).append(",");
        }
        if (sb.length() > 0) {
            sb.delete(sb.length() - 1, sb.length());
        }

        return sb.toString();
    }
}

Related

  1. collectionToCommaDelimitedString(Collection items)
  2. collectionToCommaDelimitedString(Collection list)
  3. collectionToCommaSeparatedString(Collection elementCollection)
  4. collectionToCommaSeparatedString(List list)
  5. collectionToCommaString(Collection bundleSelection)
  6. collectionToDelimitedString( Iterable iterable)
  7. collectionToDelimitedString(Collection c, String delim)
  8. collectionToDelimitedString(Collection coll, String delim)
  9. collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)