Java Collection to String collectionToDelimitedString(Collection coll, String delim)

Here you can find the source of collectionToDelimitedString(Collection coll, String delim)

Description

collection To Delimited String

License

Apache License

Declaration

public static String collectionToDelimitedString(Collection coll, String delim) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String collectionToDelimitedString(Collection coll, String delim) {
        return collectionToDelimitedString(coll, delim, "", "");
    }/*from  w  w  w  .j a v  a2  s . c  o  m*/

    public static String collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix) {
        if (coll == null) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        Iterator it = coll.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (i > 0)
                sb.append(delim);
            sb.append(prefix).append(it.next()).append(suffix);
            i++;
        }
        return sb.toString();
    }
}

Related

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