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 stringBuilder = new StringBuilder("[");
boolean first = true;
for (T t : collection) {
    if (!first) {
        stringBuilder.append(',');
    } else {
        first = true;
    if (t == null) {
        stringBuilder.append("null");
    } else {
        stringBuilder.append(t.toString());
stringBuilder.append(']');
return stringBuilder.toString();
CollectiontoString(Collection collection)
Returns a String representation of the input collection by calling each element's toString() method.
Collection<String> strings = new ArrayList<String>();
for (T item : collection)
    strings.add(item.toString());
return strings;
StringtoString(Collection collection)
Converts the collection into a comma-delimited list, Use #toString(Collection,String) if you need a different delimiter.
return toString(collection, ",");
StringtoString(Collection collection, String divider)
to String
StringBuilder sb = new StringBuilder();
boolean first = true;
for (T object : collection) {
    if (first == false) {
        sb.append(divider);
    first = false;
    sb.append(toString(object, divider));
...
StringtoString(Collection list, String delimeter)
to String
StringBuilder sb = new StringBuilder();
for (T obj : list) {
    if (sb.length() > 0 && delimeter != null) {
        sb.append(delimeter);
    sb.append(obj);
return sb.toString();
...
StringtoString(final Collection collection)
to String
if (collection == null)
    return "null";
final StringBuilder sb = new StringBuilder("{");
boolean isFirst = true;
for (final Object object : collection) {
    if (!isFirst)
        sb.append(',');
    else
...
StringtoString(final Collection collection)
to String
if (collection == null) {
    return "null";
final StringBuilder s = new StringBuilder();
for (final Iterator<?> i = collection.iterator(); i.hasNext();) {
    s.append(String.valueOf(i.next()));
    if (i.hasNext()) {
        s.append(", ");
...
StringtoString(final Collection collection, final String separator)
Create a textual representation of the given collection, separating the individual elements by the provided separator.
if (collection == null || collection.isEmpty()) {
    return "";
if (separator == null) {
    return collection.toString();
final StringBuilder builder = new StringBuilder(collection.size() * (16 + separator.length()));
boolean addSeparator = false;
...
StringtoString(final Collection objs)
Converts an array of objects to a comma separated string
return objs != null ? toString(objs.toArray()) : toString(new Object[] {});
StringtoString(final Collection values)
to String
final StringBuilder builder = new StringBuilder();
for (Object value : values) {
    builder.append(value);
    builder.append(COLLECTION_SEPARATOR);
if (values.size() > 0) {
    builder.setLength(builder.length() - COLLECTION_SEPARATOR_LENGTH);
return builder.toString();