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(String separator, Collection c)
join
if (c.isEmpty())
    return "";
StringBuilder sb = new StringBuilder();
Iterator i = c.iterator();
sb.append(i.next());
while (i.hasNext()) {
    sb.append(separator);
    sb.append(i.next());
...
Stringjoin(String separator, Collection items)
join
StringBuilder sb = new StringBuilder();
for (Object item : items)
    if (item != null)
        sb.append(separator).append(item);
return sb.substring(separator.length());
Stringjoin(String separator, Collection items)
join
StringBuilder result = new StringBuilder((separator.length() + 1) * items.size());
int i = 0;
for (Object item : items) {
    if (i > 0)
        result.append(separator);
    result.append(item.toString());
    i++;
return result.toString();
Stringjoin(String separator, Collection objs)
Stringify all the elements in the given collection, and join them with inserting the given separator.
StringBuilder builder = new StringBuilder();
String sep = "";
if (objs != null) {
    for (Object o : objs) {
        builder.append(sep).append(String.valueOf(o));
        sep = separator;
return builder.toString();
Stringjoin(String separator, Collection list)
Converts a Collection to a separator separated string
return join(separator, list, null);
Stringjoin(String separator, Collection parts)
join
StringBuilder builder = new StringBuilder(parts.size() * 16);
boolean first = true;
for (String line : parts) {
    if (!first) {
        builder.append(separator);
    if (line != null) {
        builder.append(line);
...
Stringjoin(String separator, Collection strings)
join
if (separator == null) {
    throw new IllegalArgumentException("separator cannot be null");
if (strings != null && strings.size() > 0) {
    StringBuilder sb = new StringBuilder();
    for (String s : strings) {
        sb.append(separator);
        sb.append(s);
...
Stringjoin(String separator, Collection objects)
join
if (objects.isEmpty()) {
    return "";
Iterator<T> iter = objects.iterator();
final StringBuilder ret = new StringBuilder(iter.next().toString());
while (iter.hasNext()) {
    ret.append(separator);
    ret.append(iter.next().toString());
...
Stringjoin(String separator, Collection values)
join
return join(new StringBuilder(), separator, values).toString();
Stringjoin(String token, Collection strings)
join
StringBuffer sb = new StringBuffer();
for (Iterator iter = strings.iterator(); iter.hasNext();) {
    sb.append(iter.next());
    if (iter.hasNext()) {
        sb.append(token);
return (sb.toString());
...