Java Collection to String collectionToDelimitedString(Collection col, String del)

Here you can find the source of collectionToDelimitedString(Collection col, String del)

Description

collection To Delimited String

License

Open Source License

Declaration

public static String collectionToDelimitedString(Collection<?> col, String del) 

Method Source Code

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

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

public class Main {
    public static String collectionToDelimitedString(Collection<?> col, String del) {
        if (col == null || col.isEmpty()) {
            return "";
        }/*w  w  w .jav  a 2  s .c  o  m*/
        StringBuilder sb = new StringBuilder();
        Iterator<?> it = col.iterator();
        while (it.hasNext()) {
            sb.append(it.next());
            if (it.hasNext()) {
                sb.append(del);
            }
        }
        return sb.toString();
    }
}

Related

  1. collectionToDelimitedString( Iterable iterable)
  2. collectionToDelimitedString(Collection c, String delim)
  3. collectionToDelimitedString(Collection coll, String delim)
  4. collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
  5. collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
  6. collectionToDelimitedString(Collection coll, String delim)
  7. collectionToDelimitedString(Collection coll, String delim)
  8. collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
  9. collectionToDelimitedString(Collection values, String delimiter)