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

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

Description

collection To Delimited String

License

Open Source License

Parameter

Parameter Description
coll a parameter
delim a parameter
prefix a parameter
suffix a parameter

Return

String

Declaration

public static String collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix) 

Method Source Code

//package com.java2s;

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**/* w ww.jav  a  2  s .  c o  m*/
     *
     * @param coll
     * @param delim
     * @param prefix
     * @param suffix
     * @return String
     */
    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();
    }

    /**
     *
     * @param coll
     * @param delim
     * @return String
     */
    public static String collectionToDelimitedString(Collection coll, String delim) {
        return collectionToDelimitedString(coll, delim, "", "");
    }
}

Related

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