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(CharSequence delimiter, Iterable tokens)
Returns a string containing the tokens joined by delimiters.
StringBuilder sb = new StringBuilder();
Iterator<?> it = tokens.iterator();
if (it.hasNext()) {
    sb.append(it.next());
    while (it.hasNext()) {
        sb.append(delimiter);
        sb.append(it.next());
return sb.toString();
Stringjoin(CharSequence delimiter, Iterable tokens)
join
StringBuilder sb = new StringBuilder();
boolean firstTime = true;
for (Object token : tokens) {
    if (firstTime) {
        firstTime = false;
    } else {
        sb.append(delimiter);
    sb.append(token);
return sb.toString();
Stringjoin(CharSequence delimiter, Iterable elements)
join
if (delimiter == null) {
    delimiter = "";
StringBuilder buffer = new StringBuilder();
Iterator<? extends CharSequence> it = elements.iterator();
while (it.hasNext()) {
    buffer.append(it.next());
    if (it.hasNext()) {
...
Stringjoin(CharSequence separator, Iterable strings)
Concatenates strings, using a separator.
Iterator<?> i = strings.iterator();
if (!i.hasNext()) {
    return "";
StringBuilder sb = new StringBuilder(i.next().toString());
while (i.hasNext()) {
    sb.append(separator);
    sb.append(i.next().toString());
...
Stringjoin(final CharSequence sep, final Iterable src)
join
return join(sep, new StringBuffer(), src).toString();
Stringjoin(final Iterable elements, final String separator)
join
final StringBuilder buf = new StringBuilder();
for (final CharSequence element : elements) {
    buf.append(element).append(separator);
if (buf.length() > 0) {
    buf.setLength(buf.length() - separator.length());
return new String(buf);
...
Stringjoin(final Iterable iterable, final CharSequence separator)
Joins the string representations of an Iterable collection of objects to one continues string while separating the entities with the provided separator.
Iterator<? extends Object> oIt;
if (iterable == null || (!(oIt = iterable.iterator()).hasNext())) {
    return ""; 
final StringBuilder sb = new StringBuilder(String.valueOf(oIt.next()));
while (oIt.hasNext()) {
    sb.append(separator).append(oIt.next());
return sb.toString();
Stringjoin(final Iterable objects, final CharSequence separator)
Joins the given collection of Objects using the given separator and each Object's normal toString() method.
StringBuilder result = new StringBuilder();
for (Iterator<? extends Object> iter = objects.iterator(); iter.hasNext();) {
    result.append(iter.next().toString());
    if (iter.hasNext()) {
        result.append(separator);
return result.toString();
...
Stringjoin(final Iterable tokens, final String delimiter)
join
Iterator<? extends Object> oIter;
if (tokens == null || (!(oIter = tokens.iterator()).hasNext()))
    return "";
StringBuilder oBuilder = new StringBuilder(String.valueOf(oIter.next()));
while (oIter.hasNext()) {
    oBuilder.append(delimiter).append(oIter.next());
return oBuilder.toString();
...
Stringjoin(final Iterable iterable, final String separator)
join
return join(iterable, separator, separator);