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

StringcollectionToString(Collection list, String delimiter)
collection To String
if (list.size() == 0) {
    return "";
StringBuilder output = new StringBuilder();
for (Object element : list) {
    output.append(element.toString()).append(delimiter);
String outputStr = output.toString();
...
StringcollectionToString(Collection c)
collection To String
return c.toString();
StringcollectionToString(Collection c)
collection To String
StringBuilder sb = new StringBuilder("[");
Iterator<?> i = c.iterator();
while (i.hasNext()) {
    Object o = i.next();
    if (o == null)
        sb.append("null");
    else if (o == c)
        sb.append("(this Collection)");
...
StringcollectionToString(Collection c)
An implementation of Collection.toString() suitable for classes with locks.
final Object[] a = c.toArray();
final int size = a.length;
if (size == 0)
    return "[]";
int charLength = 0;
for (int i = 0; i < size; i++) {
    Object e = a[i];
    String s = (e == c) ? "(this Collection)" : objectToString(e);
...
StringcollectionToString(Collection c)
Transforms a collection to a string representation as same as use of method collectionToString(c, null)
return collectionToString(c, null);
StringcollectionToString(Collection c, String separator)
collection To String
Iterator<?> i = c.iterator();
StringBuffer sb = new StringBuffer();
boolean isNext = false;
while (i.hasNext()) {
    if (isNext) {
        sb.append(separator);
    } else {
        isNext = true;
...
StringcollectionToString(Collection coll, String connectSymbol)
collection To String
return collectionToString(coll, connectSymbol, "", "");
StringcollectionToString(Collection collection, String separator)
collection To String
StringBuilder sb = new StringBuilder();
for (Object o : collection) {
    sb.append(o.toString());
    if (separator != null) {
        sb.append(separator);
if (sb.length() >= separator.length()) {
...
StringcollectionToString(Collection collection, String separator)
collection To String
if (collection == null || collection.size() == 0) {
    return "";
StringBuffer s = new StringBuffer(32 * collection.size());
Iterator<?> i = collection.iterator();
s.append(i.next());
while (i.hasNext()) {
    s.append(separator).append(i.next());
...
StringcollectionToString(Collection elements)
Converts the specified Collection to a string.
if (elements == null) {
    return NULL_STR;
int size = elements.size();
if (size == 0) {
    return "[]";
} else if (size == 1) {
    return "[" + elements.toArray()[0] + "]";
...