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

StringtoString(Collection collection)
to String
StringBuilder sb = new StringBuilder(collection.size() * 2);
for (Object item : collection) {
    sb.append(item).append(",");
return sb.toString();
StringtoString(Collection collection, String separator)
Flattens a collection elements to a string calling toString() on each element.
String toString = "L[null]";
if (collection != null) {
    StringBuilder sb = new StringBuilder(collection.size() * 20);
    String sep = "";
    for (Object obj : collection) {
        sb.append(sep).append(obj);
        sep = separator;
    toString = sb.toString();
return toString;
StringtoString(Collection elements, String separator)
to String
final int size = elements.size() - 1;
if (size >= 0) {
    final StringBuilder builder = new StringBuilder();
    final Iterator<?> iterator = elements.iterator();
    for (int i = 0; i < size; i++) {
        builder.append(iterator.next());
        builder.append(separator);
    return builder.append(iterator.next()).toString();
return "";
StringtoString(Collection itemList)
to String
return printf("[%s]", join(itemList, ", ", "\"%s\""));
StringtoString(Collection objects, CharSequence delimiter)
to String
StringBuilder sb = new StringBuilder();
for (Object o : objects) {
    sb.append(o.toString());
    sb.append(delimiter);
sb.setLength(sb.length() - delimiter.length());
return sb.toString();
voidtoString(Collection bytes, Collection result)
to String
for (byte[] bs : bytes) {
    result.add(toString(bs));
StringtoString(Collection collection)
to String
if (collection == null) {
    return "";
StringBuilder builder = new StringBuilder();
for (Object item : collection) {
    if (item == null) {
        continue;
    builder.append(String.valueOf(item));
return builder.toString();
StringtoString(Collection strings)
Convert a Collection of strings to a line separated list of strings.
String string = "";
for (Iterator<String> itr = strings.iterator(); itr.hasNext();) {
    string += itr.next() + "\n";
return string;
StringtoString(Collection a, String begStr, String sepStr, String endStr)
to String
int n = a.size();
if (n == 0)
    return begStr + endStr;
Iterator<T> it = a.iterator();
String s = begStr + it.next();
while (it.hasNext())
    s += sepStr + it.next();
return s + endStr;
...
StringtoString(Collection collection)
to String
StringBuilder sb = new StringBuilder();
if (collection.size() == 0) {
    return "";
for (T object : collection) {
    sb.append(object.toString());
    sb.append(",");
return sb.substring(0, sb.length() - 1);