Java Utililty Methods Collection Union

List of utility methods to do Collection Union

Description

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

Method

Collectionunion(final Collection a, final Collection b)
union
ArrayList list = new ArrayList();
Map mapa = getCardinalityMap(a);
Map mapb = getCardinalityMap(b);
Set elts = new LinkedHashSet(a);
elts.addAll(b);
Iterator it = elts.iterator();
while (it.hasNext()) {
    Object obj = it.next();
...
Collectionunion(final Collection c1, final Collection c2)
union
final List list = new ArrayList();
addAllUnique(list, c1);
addAllUnique(list, c2);
return list;
Iterableunion(final Collection... sets)
iterator over all elements contained in the union of the given sets
return () -> new Iterator() {
    int which = 0;
    Iterator it = null;
        while (which < sets.length && !it.hasNext()) {
            it = sets[which++].iterator();
    @Override
    public boolean hasNext() {
        return which < sets.length;
    @Override
    public Object next() {
        final Object result = it.next();
        while (which < sets.length && !it.hasNext()) {
            it = sets[which++].iterator();
        return result;
};
Listunion(final Collection a, final Collection b)
union
List<T> result = new ArrayList<T>(a);
result.addAll(b);
return result;
voidunionAll(final Collection collector, final T[] a, final T[] b)
Unions the two given arrays in bag logic.
int index1 = 0;
int index2 = 0;
while (true) {
    if (index1 >= a.length) {
        copyRemainder(b, index2, collector);
        break;
    } else if (index2 >= b.length) {
        copyRemainder(a, index1, collector);
...