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

StringlistToString(Collection objects)
Change list to string comma separated.
StringBuilder buffer = new StringBuilder();
int counter = 0;
for (String str : objects) {
    if (counter > 0) {
        buffer.append(",");
    counter++;
    buffer.append(str);
...
String[]listToStringArray(Collection list)
list To String Array
if (list == null) {
    return null;
} else {
    String valueArr[] = new String[list.size()];
    list.toArray(valueArr);
    return valueArr;
StringBuilderlistToStringHelper(StringBuilder sb, String sep, Collection list)
list To String Helper
for (Object line : list) {
    sb.append(line).append(sep);
if (sb.length() > 0) {
    sb.setLength(sb.length() - sep.length());
return sb;
Stringstringify(Collection collection)
stringify
StringBuilder buf = new StringBuilder();
for (Object o : collection) {
    if (buf.length() > 0)
        buf.append("\n");
    buf.append(o);
return buf.toString();
Collectionstringify(Collection collection)
Converts the given collection to a collection of strings by calling toString() on each item.
return stringify(collection, true);
StringtoStr(Collection collection)
to Str
if (collection == null)
    return "[]";
Iterator<E> i = collection.iterator();
if (!i.hasNext())
    return "[]";
StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
...
String[]toStr(Collection elements)
Converts the collection into an array of strings.
String[] strElements = null;
if (elements != null) {
    strElements = new String[elements.size()];
    Object[] oElements = elements.toArray();
    for (int i = 0; i < oElements.length; i++) {
        strElements[i] = oElements[i].toString();
return strElements;
StringtoString(Collection c)
Same as #toString(Collection,String) toString separated by ", ".
return toString(c, ", ");
StringtoString(Collection c)
to String
if (c == null)
    return "null";
StringBuffer str = new StringBuffer();
Iterator i = c.iterator();
str.append("[");
while (i.hasNext()) {
    Object o = i.next();
    if (o instanceof byte[])
...
StringtoString(Collection c, String start, String separator, String end)
An flexible alternative for converting a Collection to a String.
Iterator i = c.iterator();
StringBuilder myString = new StringBuilder();
if (start != null) {
    myString.append(start);
boolean first = true;
while (i.hasNext()) {
    if (!first) {
...