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 sep)
Join a collection of strings by a seperator
return join(strings.iterator(), sep);
Stringjoin(Collection strings, String separator)
join
return join((String[]) strings.toArray(new String[0]), separator);
Stringjoin(Collection tokens, String separator)
join
StringBuffer sb = new StringBuffer();
for (Iterator it = tokens.iterator(); it.hasNext();) {
    Object o = it.next();
    if (o != null) {
        sb.append(o.toString());
    } else {
        sb.append("NULL");
    if (it.hasNext()) {
        sb.append(separator);
return sb.toString();
Stringjoin(Collection var0, Object var1)
Borrowed from apache StringUtils.
StringBuffer var2 = new StringBuffer();
for (Iterator var3 = var0.iterator(); var3.hasNext(); var2.append(var3.next())) {
    if (var2.length() != 0) {
        var2.append(var1);
return var2.toString();
Stringjoin(Collection c, String joinWith)
Returns a string consisting of all members of a collection separated by the specified string.
if (c == null)
    return "";
StringBuilder buf = new StringBuilder();
boolean first = true;
for (Object obj : c) {
    if (first)
        first = false;
    else if (joinWith != null)
...
Stringjoin(Collection collection, String joinString)
join
StringBuilder sb = new StringBuilder();
Iterator<? extends Object> iter = collection.iterator();
while (iter.hasNext()) {
    sb.append(iter.next());
    if (iter.hasNext()) {
        sb.append(joinString);
return sb.toString();
Stringjoin(Collection collection, String separator)
Joins a collection of Objects separated by a specified separator
if (collection == null) {
    return null;
Iterator iterator = collection.iterator();
if (iterator == null) {
    return null;
if (!iterator.hasNext()) {
...
Stringjoin(Collection elements, String separator)
join
Iterator<? extends Object> iterator = elements.iterator();
if (iterator.hasNext()) {
    StringBuilder builder = new StringBuilder();
    builder.append(iterator.next().toString());
    while (iterator.hasNext()) {
        builder.append(separator);
        builder.append(iterator.next().toString());
    return builder.toString();
} else {
    return "";
Stringjoin(Collection list, String separator)
join
StringBuilder sb = new StringBuilder();
for (Object o : list) {
    sb.append(o.toString());
    sb.append(separator);
if (sb.length() > 0 && separator.length() > 0) {
    sb.delete(sb.length() - separator.length(), sb.length());
return sb.toString();
Stringjoin(Collection objects, String delim)
Join a set of strings into one string, putting the specified delimiter between adjacent strings.
String result = "";
if (objects.size() > 0) {
    String[] array;
    int i;
    Iterator it;
    i = 0;
    for (it = objects.iterator(); it.hasNext();) {
        Object o = it.next();
...