Here you can find the source of collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
Parameter | Description |
---|---|
coll | a parameter |
delim | a parameter |
prefix | a parameter |
suffix | a parameter |
public static String collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
//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, "", ""); } }