Java Utililty Methods Array Merge

List of utility methods to do Array Merge

Description

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

Method

String[]merge(String[] array1, String[] array2)
merge
if (array1 == null && array2 == null)
    return null;
if (array1 == null)
    return array2;
if (array2 == null)
    return array1;
HashSet<String> set = new HashSet<String>();
for (String string : array1)
...
String[]merge(String[] strArr1, String[] strArr2)
Merge the two given arrays of strings
if (strArr1 == null && strArr2 != null)
    return strArr2;
if (strArr2 == null && strArr1 != null)
    return strArr1;
if (strArr1 == null)
    return null;
List<String> list = new ArrayList<String>(Arrays.asList(strArr1));
list.addAll(Arrays.asList(strArr2));
...
Stringmerge(String[] strArray)
merge
return merge(strArray, ' ');
String[]merge(String[]... arrays)
merge
if (arrays == null) {
    throw new IllegalArgumentException("argument must not be null.");
List<String> result = new ArrayList<String>();
for (String[] array : arrays) {
    Collections.addAll(result, array);
return toArray(result);
...
voidmerge(T[] array, T[] temp, int left, int middle, int right)
merge
for (int i = left; i <= right; i++) {
    temp[i] = array[i];
int i = left;
int j = middle + 1;
int k = left;
while (i <= middle && j <= right) {
    if (temp[i].compareTo(temp[j]) <= 0) {
...
T[]merge(T[] array1, T[] array2)
Merge two array in a single one.
T[] merge = Arrays.copyOf(array1, array1.length + array2.length);
for (int i = 0; i < array2.length; i++) {
    merge[i + array1.length] = array2[i];
return merge;
Listmerge(T[] first, T[] second)
merge
ArrayList<T> merged = new ArrayList<>();
Collections.addAll(merged, first);
Collections.addAll(merged, second);
return merged;
T[]merge(T[] first, T[] second)
Merges two Arrays into one common array.
if (first == null) {
    return second;
if (second == null) {
    return first;
T[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
...
T[]merge(T[] left, T... right)
merge
int newLength = left.length + right.length;
T[] newArray = Arrays.copyOf(left, newLength);
for (int i = left.length; i < newLength; i++) {
    newArray[i] = right[i - left.length];
return newArray;
Listmerge(T[]... arrays)
Merges a set of arrays into a single list, maintaining original order
ArrayList<T> merged = new ArrayList<>();
for (T[] array : arrays) {
    Collections.addAll(merged, array);
return merged;