Here you can find the source of collectionToDelimitedString(Collection c, String delim)
Parameter | Description |
---|---|
c | Collection to display |
delim | delimiter to use (probably a ",") |
public static String collectionToDelimitedString(Collection c, String delim)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { /**//from w w w. j a v a 2 s . c o m * Convenience method to return a Collection as a delimited (e.g. CSV) * String. Useful for toString() implementations. * @param c Collection to display * @param delim delimiter to use (probably a ",") */ public static String collectionToDelimitedString(Collection c, String delim) { if (c == null) return "null"; StringBuffer sb = new StringBuffer(); Iterator itr = c.iterator(); int i = 0; while (itr.hasNext()) { if (i++ > 0) sb.append(delim); sb.append(itr.next()); } return sb.toString(); } }