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(final Collection list, final String delimiter)
Returns the list of strings as a single string
final StringBuilder sb = new StringBuilder();
for (final String string : list) {
    sb.append(string).append(delimiter);
sb.setLength(sb.length() - delimiter.length());
return sb.toString();
StringtoString(final Collection c)
Build a string from the collection.
if (c == null) {
    return "null";
} else if (c.isEmpty()) {
    return "";
StringBuilder sb = new StringBuilder();
for (T t : c) {
    sb.append(t.toString());
...
StringtoString(String[] collection, char separator)
GWT-ified CollectionUtils.toString.
if (collection == null) {
    return "";
StringBuilder builder = new StringBuilder();
for (String item : collection) {
    if (builder.length() > 0) {
        builder.append(separator);
    builder.append(item);
return builder.toString();
String[]toStrings(Collection vals)
to Strings
int size = vals.size(), cnt = 0;
String[] strings = new String[size];
for (Iterator itr = vals.iterator(); itr.hasNext();) {
    String s = (String) itr.next();
    if (s != null) {
        strings[cnt] = s;
        cnt++;
return strings;
ListtoStrings(Collection c)
to Strings
List<String> result = new ArrayList<String>(c.size());
for (Object e : c) {
    result.add(e.toString());
return result;
ListtoStrings(Collection objects)
Converts the given objects into a string list by invoking Object#toString() on each non-null element.
List<String> strings = new ArrayList<>();
for (T t : objects) {
    if (t == null) {
        strings.add(null);
    } else {
        strings.add(t.toString());
return strings;
String[]toStrings(final Collection stringCollection)
to Strings
switch (stringCollection.size()) {
case 0:
    return NO_STRINGS;
case 1:
    return new String[] { stringCollection.iterator().next() };
default:
    return stringCollection.toArray(new String[stringCollection.size()]);
StringtoStringWithDelimiters(Collection objects, String delim)
to String With Delimiters
StringBuffer buffer = new StringBuffer();
int index = 0;
for (Object obj : objects) {
    if (index++ > 0)
        buffer.append(delim);
    buffer.append(obj);
return buffer.toString();
...
StringtoStringWithSeparator(Collection collection, String separator)
to String With Separator
if (collection.isEmpty())
    return "";
StringBuilder b = new StringBuilder();
Iterator<?> it = collection.iterator();
while (true) {
    b.append(it.next());
    if (it.hasNext()) {
        b.append(separator);
...