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)
collection To String
if (null == list) {
    return null;
final StringBuilder sb = new StringBuilder();
for (final Object item : list) {
    if (null != item) {
        sb.append(item.toString());
return sb.toString();
StringcollectionToString(Collection list)
collection To String
if (list == null)
    return "null";
if (list.isEmpty())
    return "<empty list>";
StringBuffer sb = new StringBuffer();
int i = 0;
for (Object item : list) {
    sb.append(item.toString());
...
StringcollectionToString(Collection collection, String prefix)
collection To String
StringBuilder sb = new StringBuilder();
collectionToString(sb, collection, prefix, "[", ",", "]");
return sb.toString();
StringcollectionToString(Collection collection)
collection To String
StringBuilder builder = new StringBuilder();
for (Object obj : collection) {
    builder.append(String.format("%s\n", obj.toString()));
return builder.toString();
StringcollectionToString(Collection collection)
Returns a collection of Strings as a comma-delimitted list of strings.
if (collection == null || collection.isEmpty()) {
    return "";
StringBuilder buf = new StringBuilder();
String delim = "";
for (String element : collection) {
    buf.append(delim);
    buf.append(element);
...
StringcollectionToString(Collection collection)
Returns a collection of Strings as a comma-delimitted list of strings.
if (collection == null || collection.isEmpty()) {
    return "";
StringBuilder buf = new StringBuilder();
String delim = "";
for (String element : collection) {
    buf.append(delim);
    buf.append(element);
...
StringcollectionToString(Collection collection)
Returns a collection of Strings as a comma-delimitted list of strings.
if (collection == null || collection.isEmpty()) {
    return "";
StringBuilder buf = new StringBuilder();
String delim = "";
for (String element : collection) {
    buf.append(delim);
    buf.append(element);
...
StringcollectionToString(Collection col, String sep)
collection To String
StringBuilder sb = new StringBuilder(512);
Iterator<T> iter = col.iterator();
while (iter.hasNext()) {
    sb.append(iter.next());
    if (iter.hasNext()) {
        sb.append(sep);
return sb.toString();
StringcollectionToString(Collection collection)
collection To String
StringBuilder sb = new StringBuilder();
sb.append('{');
boolean isFirstElement = true;
for (T element : collection) {
    if (isFirstElement) {
        isFirstElement = false;
    } else {
        sb.append(',');
...
StringcollectionToString(Collection list)
collection To String
return collectionToString(list, ", ");