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

StringcollectionToCommaSeparatedString(Collection elementCollection)
Collection to comma separated string string.
List<String> list = new ArrayList<>();
elementCollection.stream().forEach(element -> list.add(element));
return listToSeparatedString(list, ',');
StringcollectionToCommaSeparatedString(List list)
collection To Comma Separated String
return collectionToString(list, ", ");
StringcollectionToCommaString(Collection bundleSelection)
collection To Comma String
StringBuffer sb = new StringBuffer();
for (Iterator it = bundleSelection.iterator(); it.hasNext();) {
    if (sb.length() > 0)
        sb.append(',');
    sb.append(it.next().toString());
return sb.toString();
StringcollectionToCSString(Collection col)
Transform collection to comma split string.
if (col == null) {
    return null;
StringBuilder sb = new StringBuilder();
for (E e : col) {
    sb.append(e).append(",");
if (sb.length() > 0) {
...
StringcollectionToDelimitedString(Iterable iterable)
collection To Delimited String
return collectionToDelimitedString(iterable, ",");
StringcollectionToDelimitedString(Collection c, String delim)
Convenience method to return a Collection as a delimited (e.g.
if (c == null)
    return "null";
StringBuffer sb = new StringBuffer();
Iterator itr = c.iterator();
int i = 0;
while (itr.hasNext()) {
    if (i++ > 0)
        sb.append(delim);
...
StringcollectionToDelimitedString(Collection coll, String delim)
collection To Delimited String
return collectionToDelimitedString(coll, delim, "", "");
StringcollectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
Convenience method to return a Collection as a delimited (e.g.
if (coll == null || coll.isEmpty()) {
    return "";
StringBuffer sb = new StringBuffer();
Iterator it = coll.iterator();
while (it.hasNext()) {
    sb.append(prefix).append(it.next()).append(suffix);
    if (it.hasNext()) {
...
StringcollectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
collection To Delimited String
if (coll == null) {
    return "";
StringBuffer sb = new StringBuffer();
Iterator it = coll.iterator();
int i = 0;
while (it.hasNext()) {
    if (i > 0) {
...
StringcollectionToDelimitedString(Collection col, String del)
collection To Delimited String
if (col == null || col.isEmpty()) {
    return "";
StringBuilder sb = new StringBuilder();
Iterator<?> it = col.iterator();
while (it.hasNext()) {
    sb.append(it.next());
    if (it.hasNext()) {
...