Java Utililty Methods String Array Combine

List of utility methods to do String Array Combine

Description

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

Method

String[]combine(final String[] left, final String[] right)
combine
final String[] rv = new String[left.length + right.length];
for (int pos = 0; pos < left.length; ++pos)
    rv[pos] = left[pos];
for (int pos = 0; pos < right.length; ++pos)
    rv[left.length + pos] = right[pos];
return rv;
Stringcombine(String sep, String... s)
combine
String ret = "";
if (s.length > 0) {
    ret = s[0];
for (int i = 1; i < s.length; i++) {
    ret += sep + s[i];
return ret;
...
Stringcombine(String style1, String style2)
Combines multiple styles
return style1 + "," + style2;
Stringcombine(String... s)
"a", "b", "c" -> "a b c a-b a-b-c" "a", "b", null -> "a b a-b"
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length; i++) {
    if (s[i] != null) {
        sb.append(s[i]);
        if (i < s.length - 1 && s[i + 1] != null) {
            sb.append(' ');
for (int j = 1; j < s.length; j++) {
    if (s[j] != null) {
        sb.append(' ');
        for (int i = 0; i <= j; i++) {
            sb.append(s[i]);
            if (i < j && s[i + 1] != null) {
                sb.append('-');
return sb.toString();
Stringcombine(String... vals)
combine
StringBuilder buf = new StringBuilder();
for (String val : vals) {
    if (buf.length() > 0)
        buf.append(", ");
    buf.append(val);
return buf.toString();
String[]combine(String[] a, String[] b, String glue)
Combined string elements from two arrays into a single array, gluing together elements of the same index with a delimiter string.
String[] result = new String[Math.min(a.length, b.length)];
for (int i = 0; i < result.length; ++i) {
    result[i] = a[i] + glue + b[i];
return result;
String[]combine(String[] array1, String[] array2)
Combine to string arrays.
if (array1 == null || array1.length == 0)
    return array2;
else if (array2 == null || array2.length == 0)
    return array1;
String[] result = new String[array1.length + array2.length];
System.arraycopy(array1, 0, result, 0, array1.length);
System.arraycopy(array2, 0, result, array1.length, array2.length);
return result;
...
Stringcombine(String[] strs, String delimeter)
combine
StringBuilder sb = new StringBuilder(strs.length * (20 + delimeter.length()));
for (String str : strs) {
    sb.append(str);
    sb.append(delimeter);
return sb.toString();
Stringcombine(String[] values, String delimiter)
Combines the strings values in the string array into one single string, delimited by the specified delimiter.
if (values == null) {
    throw new NullPointerException("values array is null");
if (values.length == 0) {
    return "";
StringBuffer result = new StringBuffer();
for (int i = 1; i < values.length; i++) {
...
Stringcombine(String[] values, String regex)
combine
if (values == null) {
    return null;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < values.length; i++) {
    if (values[i] == null) {
        continue;
    sb.append(values[i]);
    if (i < values.length - 1) {
        sb.append(regex);
return sb.toString();