Java Utililty Methods Collection to String

List of utility methods to do Collection to String

Description

The list of methods to do Collection to String are organized into topic(s).

Method

StringcollectionToDelimitedString(Collection coll, String delim)
Convert a Collection into a delimited String (e.g.
return collectionToDelimitedString(coll, delim, "", "");
StringcollectionToDelimitedString(Collection coll, String delim)
Convenience method to return a Collection as a delimited (e.g.
return collectionToDelimitedString(coll, delim, "", "");
StringcollectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
Convenience method to return a Collection as a delimited (e.g.
if (coll == null || coll.isEmpty()) {
    return "";
StringBuilder sb = new StringBuilder();
Iterator<?> it = coll.iterator();
while (it.hasNext()) {
    sb.append(prefix).append(it.next()).append(suffix);
    if (it.hasNext()) {
...
StringcollectionToDelimitedString(Collection values, String delimiter)
collection To Delimited String
StringBuffer str = new StringBuffer();
for (String val : values) {
    if (str.length() > 0) {
        str.append(delimiter);
    str.append(val);
return str.toString();
...
StringcollectionToStr(Collection collection)
collection To Str
return collectionToStr(collection, null, null, null, true);
StringCollectionToStr(Collection coll)
Collection To Str
StringBuffer sb = new StringBuffer();
int i = 0;
for (String string : coll) {
    if (i > 0) {
        sb.append(",");
    i++;
    sb.append(string);
...
StringcollectionToStr(Collection collection)
collection To Str
StringBuilder result = new StringBuilder("");
if (collection == null) {
    return result.toString();
T[] array = (T[]) collection.toArray();
for (int i = 0; i < array.length; i++) {
    result.append(array[i]);
    if (i != array.length - 1) {
...
StringcollectionToString(Collection collection)
Transform a collection of objects to a whitespace delimited String.
return toStringBuilder(collection, " ").toString();
StringcollectionToString(@SuppressWarnings("rawtypes") Collection coll)
Take a collection of anything and return it formatted as a string.
if (coll == null)
    return "";
StringBuffer sb = new StringBuffer();
sb.append("[");
for (Object o : coll) {
    sb.append(o.toString());
    sb.append(",");
sb.append("]");
return sb.toString();
StringcollectionToString(Collection c)
collection To String
StringBuffer buff = new StringBuffer();
int i = 0;
int size = c.size();
for (Iterator iter = c.iterator(); iter.hasNext();) {
    Object object = iter.next();
    if (size > 1 && i == (size - 1)) {
        buff.append("and ");
    buff.append(object);
    if (i < (size - 1)) {
        if (size > 2) {
            buff.append(", ");
        } else {
            buff.append(" ");
    i++;
return buff.toString();