Java Utililty Methods Array Join

List of utility methods to do Array Join

Description

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

Method

Object[]join(Object[]... arrays)
join
int size = totalSize(arrays);
Object[] result = new Object[size];
int i = 0;
for (Object[] array : arrays) {
    if (array != null) {
        for (int j = 0; j < array.length; ++j, ++i) {
            result[i] = array[j];
return result;
Stringjoin(String delimiter, Object[] strings)
join
if (strings == null)
    return "";
int len = strings.length;
String ans = "";
for (int i = 0; i < len; ++i) {
    if (i > 0)
        ans += delimiter;
    ans += strings[i];
...
Stringjoin(String delimiter, short[] array)
Joins an array of shorts, separated by a delimiter.
if (array == null) {
    return null;
StringBuilder buf = new StringBuilder();
for (int i = 0; i < array.length; i++) {
    buf.append(array[i]);
    if (i + 1 < array.length) {
        buf.append(delimiter);
...
Stringjoin(String delimiter, String[] array)
join
StringBuilder sb = new StringBuilder();
int counter = 0;
for (String element : array) {
    sb.append(counter++ > 0 ? delimiter : "");
    sb.append(element);
return sb.toString();
Stringjoin(String delimiter, String[] elements)
Join an array of String elements into a single String.
StringBuilder ret = new StringBuilder();
boolean firstIteration = true;
for (String s : elements) {
    if (!firstIteration) {
        ret.append(delimiter);
    } else {
        firstIteration = false;
    ret.append(s);
return ret.toString();
Stringjoin(String delimiter, String[] s)
join
int ls = s.length;
switch (ls) {
case 0:
    return "";
case 1:
    return s[0];
case 2:
    return s[0].concat(delimiter).concat(s[1]);
...
StringBufferjoin(String glue, String[] strings)
Takes a string 'glue' and array of strings, and returns a StringBuffer containing the strings joined with the glue between each of them.
return join(glue, strings, 0, strings.length - 1);
Stringjoin(String glue, String[] strings)
join
return join(glue, asList(strings));
Stringjoin(String s, String[] arr, int off, int end)
join
if (off < 0 || end > arr.length) {
    throw new IllegalArgumentException("Invalid indices");
if (end <= off) {
    return "";
StringBuilder sb = new StringBuilder();
for (int i = off; i < end - 1; i++) {
...
Stringjoin(String s[], String glue)
Join the given strings with given glue
StringBuilder buffer = new StringBuilder();
List list = Arrays.asList(s);
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
    buffer.append(iterator.next());
    if (iterator.hasNext())
        buffer.append(glue);
return buffer.toString();