Here you can find the source of tooDelimitedString(final Collection coll, final String delim, final String prefix, final String suffix)
Parameter | Description |
---|---|
coll | Collection to display |
delim | delimiter to use (probably a ",") |
prefix | string to start each element with |
suffix | string to end each element with |
public static String tooDelimitedString(final Collection coll, final String delim, final String prefix, final String suffix)
//package com.java2s; //License from project: LGPL import java.util.*; public class Main { /**//w w w . ja v a 2 s. c o m * Convenience method to return a Collection as a delimited (e.g. CSV) * String. E.g. useful for toString() implementations. * * @param coll Collection to display * @param delim delimiter to use (probably a ",") * @param prefix string to start each element with * @param suffix string to end each element with */ public static String tooDelimitedString(final Collection coll, final String delim, final String prefix, final String suffix) { if (coll == null) { return ""; } final StringBuilder sb = new StringBuilder(); 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(); } public static String toString(final Collection list) { final StringBuilder sb = new StringBuilder(); if (null != list) { for (final Object item : list) { if (null != item) { sb.append(item); } } } return sb.toString(); } public static String toString(final Object[] list) { final StringBuilder sb = new StringBuilder(); if (null != list) { for (final Object item : list) { if (null != item) { sb.append(item); } } } return sb.toString(); } }