Java Utililty Methods Collection Join

List of utility methods to do Collection Join

Description

The list of methods to do Collection Join are organized into topic(s).

Method

Stringjoin(Collection strings, String separator)
Joins the elements of the provided Collection collection into a single String string , using the provided separator and string elements.
StringBuilder sb = new StringBuilder();
if (strings != null) {
    Iterator<? extends Object> i = strings.iterator();
    while (i.hasNext()) {
        sb.append(i.next());
        if (i.hasNext()) {
            sb.append(separator);
return sb.toString();
Stringjoin(Collection strs, String separator)
join
StringBuilder result = null;
for (Object o : strs) {
    if (result == null) {
        result = new StringBuilder();
    } else {
        result.append(separator);
    result.append(o);
...
Stringjoin(Collection c, String delim)
Similar to perl's join() method on lists, but works with all collections.
StringBuilder retval = new StringBuilder();
Iterator<?> itr = c.iterator();
if (itr.hasNext())
    retval.append(itr.next());
else
    return "";
while (itr.hasNext()) {
    retval.append(delim);
...
Stringjoin(Collection c, String delimiter)
Returns a String formed by the delimited results of calling toString over a collection.
StringBuffer sb = new StringBuffer();
boolean needComma = false;
for (Object o : c) {
    if (needComma) {
        sb.append(delimiter);
    needComma = true;
    sb.append(o.toString());
...
Stringjoin(Collection c, String insert)
Return the string created by inserting insert between the members of c .
return join(c, insert, insert);
Stringjoin(Collection c, String separator)
Join operation on a collection
if (!isSet(separator)) {
    throw new IllegalArgumentException("Separator is null or empty");
if (c == null || c.size() == 0) {
    return "";
StringBuilder sb = new StringBuilder();
for (Object element : c) {
...
Stringjoin(Collection col, String delim)
join
StringBuilder sb = new StringBuilder();
Iterator<?> iter = col.iterator();
if (iter.hasNext())
    sb.append(iter.next().toString());
while (iter.hasNext()) {
    sb.append(delim);
    sb.append(iter.next().toString());
return sb.toString();
Stringjoin(Collection col, String separator)
join
StringBuilder sb = new StringBuilder();
Iterator<?> it = col.iterator();
if (!col.isEmpty()) {
    Object obj = it.next();
    sb.append(obj.toString());
while (it.hasNext()) {
    Object obj = it.next();
...
Stringjoin(Collection coll, String delim)
Convenience method to return a Collection as a delimited (e.g.
return join(coll, delim, "", "");
Stringjoin(Collection collection, String delimiter)
Joins a Collection of typed objects using their toString method, separated by delimiter
if (collection == null || collection.isEmpty()) {
    return EMPTY_STRING;
} else if (delimiter == null) {
    delimiter = EMPTY_STRING;
StringBuilder builder = new StringBuilder();
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
...