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, String separator, int fixedLength)
Convert array into string in table format.
Iterator iter;
if (collection == null || (!(iter = collection.iterator()).hasNext())) {
    return "";
StringBuilder sb = new StringBuilder(matchLength(String.valueOf(iter.next()), "", fixedLength));
while (iter.hasNext()) {
    sb.append(separator).append(matchLength(String.valueOf(iter.next()), "", fixedLength));
return sb.toString();
StringtoString(Collection objects)
to String
String string = "";
for (Object object : objects) {
    string = string + object.toString() + ", ";
try {
    string = string.substring(0, string.length() - 2);
} catch (StringIndexOutOfBoundsException sioobe) {
    return "";
...
StringtoString(Collection setOfTests)
to String
String errorSet = "[\n";
for (Object test : setOfTests) {
    errorSet += test + ", \n";
errorSet += "]";
return errorSet;
StringtoString(Collection softwareTags)
to String
StringBuffer sb = new StringBuffer();
for (Iterator i = softwareTags.iterator(); i.hasNext();) {
    Object softwareTag = i.next();
    String tagName = null;
    sb.append(SPACE);
    if (tagName.indexOf(SPACE) != -1) {
        sb.append(QUOTE).append(tagName).append(QUOTE);
    } else {
...
StringtoString(Collection collection)
Method description
StringBuilder sb = new StringBuilder();
if (collection != null) {
    Iterator<? extends Object> it = collection.iterator();
    while (it.hasNext()) {
        sb.append(it.next());
        if (it.hasNext()) {
            sb.append(", ");
return sb.toString();
StringtoString(Collection collection, String prefix, String suffix)
to String
StringBuilder sb = new StringBuilder();
for (Object line : collection) {
    sb.append(prefix);
    sb.append(line.toString());
    sb.append(suffix);
return sb.toString();
StringtoString(Collection c)
Returns the given Collection as formatted String
StringBuilder buffer = new StringBuilder();
Iterator it = c.iterator();
for (int i = 0; it.hasNext(); i++) {
    buffer.append(i).append(": ").append(it.next()).append('\n');
if (buffer.length() > 1) {
    buffer.setLength(buffer.length() - 1);
return buffer.toString();
StringtoString(Collection c)
to String
if (c == null) {
    return STRING_NULL;
if (c.isEmpty()) {
    return STRING_LIST_EMPTY;
StringBuilder string = new StringBuilder(4 * c.size());
boolean sep = false;
...
StringtoString(Collection collection)
to String
if (collection == null || collection.isEmpty()) {
    return "";
StringBuilder stringBuilder = new StringBuilder("[");
for (Object object : collection) {
    if (object instanceof Collection<?>) {
        stringBuilder.append(toString((Collection<?>) object));
    } else {
...
StringtoString(Collection collection)
to String
if (isEmpty(collection)) {
    return "";
StringBuilder sb = new StringBuilder();
for (Object o : collection) {
    sb.append(o.toString()).append(", ");
sb.setLength(sb.length() - 2);
...