Java Collection Convert toDelimitedString(Collection coll, String delim)

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

Description

to Delimited String

License

LGPL

Declaration

public static String toDelimitedString(Collection<String> coll, String delim) 

Method Source Code


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

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

public class Main {
    public static String toDelimitedString(Collection<String> coll, String delim) {
        return toDelimitedString(coll, delim, "", "");
    }//from  ww w.  ja v  a 2 s.c o  m

    public static String toDelimitedString(Collection<String> coll, String delim, String prefix, String suffix) {
        if (coll == null || coll.size() == 0)
            return "";
        StringBuilder sb = new StringBuilder();
        Iterator<String> it = coll.iterator();
        while (it.hasNext()) {
            sb.append(prefix).append(it.next()).append(suffix);
            if (it.hasNext()) {
                sb.append(delim);
            }
        }
        return sb.toString();
    }
}

Related

  1. toCommaString(Collection c)
  2. toCsvString(Collection collection)
  3. toCSVString(Collection theCollection, String theSeparator)
  4. toDelimitedList(Collection values, String delimiter)
  5. toDelimitedString(Collection c, String delimiter)
  6. toDelimitedString(final Collection coll, final String delim)
  7. toDoubles(Collection numbers)
  8. toEnumeration(final Collection collection)
  9. toEscapedStringWithDelimiters(Collection objects, String delim)