Java Utililty Methods Array Union

List of utility methods to do Array Union

Description

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

Method

String[]domainUnion(String[] a, String[] b)
Clever union of String arrays.
int cIinA = numInts(a);
int cIinB = numInts(b);
if (cIinA == 0 && cIinB == 0 
        || cIinA == a.length && cIinB == b.length) 
    return union(a, b, cIinA == 0);
int[] ai = toInt(a, 0, cIinA);
Arrays.sort(ai); 
int[] bi = toInt(b, 0, cIinB);
...
String[]domainUnion(String[] a, String[] b)
Clever union of String arrays.
int cIinA = numInts(a);
int cIinB = numInts(b);
if (cIinA == 0 && cIinB == 0 
        || cIinA == a.length && cIinB == b.length) 
    return union(a, b, cIinA == 0);
int[] ai = toInt(a, 0, cIinA);
Arrays.sort(ai); 
int[] bi = toInt(b, 0, cIinB);
...
StringgetUnionStr(String[] strAry, String unionChar, String appendChar)
get Union Str
StringBuffer ret = new StringBuffer();
for (int i = 0; i < strAry.length; i++) {
    if (i != 0)
        ret.append(unionChar);
    ret.append(appendChar + strAry[i] + appendChar);
return ret.toString();
int[]union(int[] a, int[] b)
Returns a union of given sorted arrays.
assert a != null && b != null : "Union expect non-null input!";
int[] r = new int[a.length + b.length];
int ia = 0, ib = 0, i = 0;
while (ia < a.length && ib < b.length) {
    int c = a[ia] - b[ib];
    if (c < 0)
        r[i++] = a[ia++];
    else if (c == 0) {
...
int[]union(int[]... arrays)
Returns an array with all elements in input arrays (no repetitions).
Set<Integer> unionSet = new LinkedHashSet<Integer>();
for (int[] array : arrays)
    for (int j = 0; j < array.length; j++)
        unionSet.add(array[j]);
return toArray(unionSet);
String[]unionOfStringArrays(String x[], String y[])
union Of String Arrays
Set<String> set = new LinkedHashSet<String>();
for (String s : x)
    set.add(s);
for (String s : y)
    set.add(s);
String[] arr = new String[set.size()];
set.toArray(arr);
return arr;
...