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(final String sep, final Collection c)
Join a bunch of objects into a string delimited by the separator
if (c == null) {
    return null;
if (c.size() == 1) {
    return String.valueOf(c.iterator().next());
if (c.size() == 0) {
    return "";
...
Stringjoin(final String sep, final Collection strs)
Join the given strings, separated by the given separator.
final StringBuilder sb = new StringBuilder();
String s = "";
for (final String str : strs) {
    sb.append(s).append(str);
    s = sep;
return sb.toString();
Stringjoin(final String separator, final Collection objects)
Returns a string of the form elt1.toString() [sep elt2.toString() ...
if (objects.isEmpty()) { 
    return "";
} else {
    final Iterator<T> iter = objects.iterator();
    final T first = iter.next();
    if (!iter.hasNext()) 
        return first.toString();
    else { 
...
Stringjoin(final String separator, final Collection objects)
Returns a string of the form elt1.toString() [sep elt2.toString() ...
if (objects.isEmpty()) { 
    return "";
} else {
    final Iterator<T> iter = objects.iterator();
    final T first = iter.next();
    if (!iter.hasNext()) 
        return first.toString();
    else { 
...
Stringjoin(final String separator, final Collection objects)
Returns a string of the form elt1.toString() [sep elt2.toString() ...
if (objects.isEmpty()) { 
    return "";
} else {
    final Iterator<T> iter = objects.iterator();
    final T first = iter.next();
    if (!iter.hasNext()) 
        return first.toString();
    else { 
...
Stringjoin(Iterable collection, String delimiter)
Concatenates the elements from the collection to one string.
return join(collection.iterator(), delimiter);
Stringjoin(Iterable collection)
join
return join(collection, DEFAULT_DELIMITER);
Stringjoin(String c, Collection d)
Similar to join / implode in php.
StringBuilder res = new StringBuilder();
boolean notFirst = false;
for (Iterator i = d.iterator(); i.hasNext();) {
    if (notFirst)
        res.append(c);
    else
        notFirst = true;
    res.append(i.next());
...
Stringjoin(String delim, Collection list)
join
return join(delim, list.toArray());
Stringjoin(String delim, Collection col)
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();