Java Utililty Methods Iterable Join

List of utility methods to do Iterable Join

Description

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

Method

Stringjoin(Iterable items)
Joins the given sequence of strings with a command and space between each consecutive pair.
return join(items, ", ");
Stringjoin(Iterable items, String delimiter)
join
StringBuffer buffer = new StringBuffer();
Iterator<?> iter = items.iterator();
if (iter.hasNext()) {
    buffer.append(iter.next().toString());
    while (iter.hasNext()) {
        buffer.append(delimiter);
        buffer.append(iter.next().toString());
return buffer.toString();
Stringjoin(Iterable items, String separator)
Same as #join(String[],String) but expecting an Iterable instead of an array
final StringBuilder builder = new StringBuilder();
final Iterator<?> it = items.iterator();
while (it.hasNext()) {
    builder.append(it.next().toString());
    if (it.hasNext()) {
        builder.append(separator);
return builder.toString();
Stringjoin(Iterable iterable, String separator)
join
return iterable == null ? null : join(iterable.iterator(), separator);
Stringjoin(Iterable iterable, String separator)
Joins the elements of the provided Iterable into a single String containing the provided elements.
StringBuffer buffer = new StringBuffer();
Iterator<?> iterator = iterable.iterator();
while (iterator.hasNext()) {
    buffer.append(iterator.next());
    if (iterator.hasNext()) {
        buffer.append(separator);
return buffer.toString();
Stringjoin(Iterable list, String delimiter)
join
if (list == null)
    return null;
StringBuilder builder = new StringBuilder();
for (Iterator<?> i = list.iterator(); i.hasNext();) {
    Object value = i.next();
    builder.append(value);
    if (i.hasNext())
        builder.append(delimiter);
...
Stringjoin(Iterable objects)
join
Iterator<?> iterator = objects.iterator();
if (!iterator.hasNext()) {
    return "";
StringBuilder buffer = new StringBuilder(iterator.next().toString());
while (iterator.hasNext()) {
    buffer.append(iterator.next().toString());
return buffer.toString();
Stringjoin(Iterable objects, String delimiter)
join
Iterator<?> i = objects.iterator();
if (!i.hasNext()) {
    return "";
StringBuilder result = new StringBuilder();
result.append(i.next());
while (i.hasNext()) {
    result.append(delimiter).append(i.next());
...
Stringjoin(Iterable parts, String delimiter)
Joins the String values of the contents of the Object array (parts) by inserting (delimiter) between each String.
if (parts == null)
    return null;
if (delimiter == null)
    throw new NullPointerException(
            "The delimiter cannnot be null. Use an empty string if you want no delimiter.");
StringBuilder result = new StringBuilder();
String currentDelim = null;
for (Object part : parts) {
...
Stringjoin(Iterable target, String separator)
join
StringBuilder sb = new StringBuilder();
Iterator<?> it = target.iterator();
if (it.hasNext()) {
    sb.append(it.next());
    while (it.hasNext()) {
        sb.append(separator);
        sb.append(it.next());
return sb.toString();