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 c, String left, String right, String separator)
Return a String object join all String object in param c, and add param left and param right to every String object on the left side and right side, separaing with param separator.
if (c == null || c.size() == 0) {
    return null;
StringBuffer sb = new StringBuffer();
boolean firstFlag = true;
for (Iterator it = c.iterator(); it.hasNext();) {
    if (firstFlag) {
        firstFlag = false;
...
Stringjoin(Collection c, String separator)
join
boolean was = false;
String result = "";
for (Object o : c) {
    if (was)
        result += separator;
    result += o;
    was = true;
return result;
Stringjoin(Collection col, char sep)
Join the String representations of a collection of objects, with the specified separator.
if (col.isEmpty()) {
    return "";
StringBuffer buffer = new StringBuffer();
boolean first = true;
for (Object o : col) {
    if (first) {
        first = false;
...
Stringjoin(Collection coll, String separator)
join
StringBuilder sb = new StringBuilder();
for (Iterator it = coll.iterator();;) {
    sb.append(it.next().toString());
    if (it.hasNext()) {
        sb.append(separator);
    } else {
        break;
return sb.toString();
Stringjoin(Collection collection)
This method joins each value in the collection with a tab character as the delimiter.
return join(collection, "\t");
Stringjoin(Collection collection, String separator)
Join an collection of objects with a separator that appears after every instance in the list -including at the end
return join(collection, separator, true);
Stringjoin(Collection collection, String separator)

Joins the elements of the provided Collection into a single String containing the provided elements.

if (collection == null) {
    return null;
if (collection.isEmpty()) {
    return ""; 
final Iterator iterator = collection.iterator();
final Object first = iterator.next();
...
Stringjoin(Collection collection, String separator)

Joins the elements of the provided Collection into a single String containing the provided elements.

No delimiter is added before or after the list.

if (collection == null) {
    return null;
return join(collection.iterator(), separator);
Stringjoin(Collection collection, String separator)
join
if (collection == null) {
    return null;
StringBuffer buffer = new StringBuffer();
for (Iterator iterator = collection.iterator(); iterator.hasNext(); buffer
        .append(iterator.next().toString())) {
    if (buffer.length() != 0) {
        buffer.append(separator);
...
Stringjoin(Collection collection, String separator, boolean trailing)
join
StringBuilder b = new StringBuilder();
collection.stream().forEach((o) -> b.append(o.toString()).append(separator));
return (trailing || b.length() == 0) ? b.toString() : (b.substring(0, b.length() - 1));