Java Utililty Methods String Join

List of utility methods to do String Join

Description

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

Method

Stringjoin(String delimiter, T... array)
join
return join(delimiter, Arrays.asList(array));
Stringjoin(String glue, Iterable items)
join
StringBuilder ret = new StringBuilder();
boolean first = true;
for (String item : items) {
    if (first) {
        first = false;
    } else {
        ret.append(glue);
    ret.append(item);
return ret.toString();
Stringjoin(String glue, String... str)
Combine strings with a common string
if (str.length > 0) {
    StringBuilder sb = new StringBuilder(str[0]);
    for (int i = 1; i < str.length; i++)
        sb.append(glue).append(str[i]);
    return sb.toString();
} else
    return "";
Stringjoin(String joiner, String... toJoin)
join
return join(joiner, Arrays.asList(toJoin), 0);
Stringjoin(String s, Object... objects)
join
if (objects.length == 0) {
    return "";
StringBuilder sb = new StringBuilder(objects[0].toString());
for (int i = 1; i < objects.length; i++) {
    sb.append(s).append(objects[i]);
return sb.toString();
...
Stringjoin(String sep, Object... pieces)
Turns a sequence of objects into a string, delimited by sep .
if ((pieces.length == 1) && (pieces[0] instanceof Collection)) {
    return internalJoin(sep, (Collection<Object>) pieces[0]);
} else {
    return internalJoin(sep, Arrays.asList(pieces));
Stringjoin(String separator, CharSequence... elements)
join
StringBuilder builder = new StringBuilder();
for (int i = 0; i < elements.length; i++) {
    builder.append(elements[i]);
    if (i < elements.length - 1) {
        builder.append(separator);
return builder.toString();
...
Stringjoin(String separator, Collection strings)
Joins a number of strings together to form one long string, with the optional separator inserted between each of them.
StringBuilder builder = new StringBuilder();
for (String string : strings) {
    if (builder.length() > 0 && separator != null)
        builder.append(separator);
    builder.append(string);
return builder.toString();
Stringjoin(String separator, List objects)
join
StringBuilder builder = new StringBuilder();
for (int i = 0; i < objects.size(); i++) {
    builder.append(objects.get(i));
    if (i != objects.size() - 1)
        builder.append(separator);
return builder.toString();
Stringjoin(String separator, Object... objects)
join
StringBuilder sb = new StringBuilder();
for (Object o : objects) {
    sb.append(o.toString()).append(separator);
return sb.toString().trim();