Java Utililty Methods List Join

List of utility methods to do List Join

Description

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

Method

StringstringJoin(List list, String separator)
Join a list of objects to a string with a given separator by calling Object.toString() on the elements.
StringBuilder ret = new StringBuilder();
boolean first = true;
for (Object o : list) {
    if (!first) {
        ret.append(separator);
    ret.append(o);
    first = false;
...
StringstringJoin(List list, String sep)
string Join
if (list == null)
    return null;
StringBuilder sb = new StringBuilder();
for (String s : list) {
    if (sb.length() > 0)
        sb.append(sep);
    sb.append(s);
return sb.toString();
StringtrimAndJoin(List values, String delimiter)
trim And Join
if (values == null || values.isEmpty())
    return null;
StringBuilder delimited = new StringBuilder();
Iterator<Object> valuesI = values.iterator();
while (valuesI.hasNext()) {
    delimited.append(valuesI.next().toString().trim());
    if (valuesI.hasNext())
        delimited.append(delimiter);
...