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

String[]collectionToStringArray(Collection objs)
collection To String Array
if (objs == null)
    return null;
String[] ret = new String[objs.size()];
int idx = 0;
for (Object o : objs) {
    ret[idx] = o.toString();
    idx++;
return ret;
String[]collectionToStringArray(List values)
collection To String Array
String[] array = new String[values.size()];
int index = 0;
for (String value : values) {
    array[index] = value;
    index++;
return array;
ListcollectionToStringList(Collection c)
Take a collection, return a list containing the string value of every element in the collection.
List<String> l = new ArrayList<String>(c.size());
for (Object o : c) {
    l.add(o.toString());
return l;
ListcollectionToStringList(Collection c)
Take a collection, return a list containing the string value of every element in the collection.
List<String> l = new ArrayList<>(c.size());
for (Object o : c) {
    l.add(o.toString());
return l;
StringcollectionToStringList(Collection list, String delimiter)
Takes a collection of objects and converts them to a list where each item is converted to a string by its toString() method.
boolean firstPass = true;
StringBuilder resultBuilder = new StringBuilder();
for (Object item : list) {
    if (firstPass) {
        firstPass = false;
    } else {
        resultBuilder.append(delimiter);
    resultBuilder.append(item.toString());
return resultBuilder.toString();
StringcommaSeparatedList(Collection objects)
comma Separated List
StringBuilder sb = new StringBuilder();
Iterator<?> iter = objects.iterator();
while (iter.hasNext()) {
    sb.append(iter.next());
    sb.append(", ");
if (sb.length() > 2) {
    sb.deleteCharAt(sb.length() - 1);
...
StringcommaSeparatedString(List list, boolean quoteStrings)
Creates a comma-separated String from the given List of String objects.
if (list == null) {
    return null;
StringBuffer buffer = new StringBuffer();
for (int index = 0; index < list.size(); index++) {
    if (index > 0) {
        buffer.append(',');
    String string = (String) list.get(index);
    if (quoteStrings) {
        string = quotedString(string);
    buffer.append(string);
return buffer.toString();
StringconvertCollectionToCommaDelimitedString(Collection collection)
convert Collection To Comma Delimited String
StringBuffer sb = new StringBuffer();
if (collection != null) {
    Iterator iter = collection.iterator();
    int count = 0;
    while (iter.hasNext()) {
        String item = (String) iter.next();
        if (count != 0) {
            sb.append(", ");
...
StringconvertCollectionToString(Collection strings, String separator)
convert Collection To String
String result = "";
boolean first = true;
for (String s : strings) {
    if (first) {
        result += s;
        first = false;
    } else {
        result += separator + s;
...
StringconvertCollectionToString(Collection coll, String delimiter)
convert Collection To String
if (coll == null) {
    return null;
StringBuilder sb = new StringBuilder();
for (String value : coll) {
    sb.append(value);
    sb.append(delimiter);
if (sb.length() > 0) {
    sb.delete(sb.length() - delimiter.length(), sb.length());
return sb.toString();