Java Utililty Methods Collection Difference

List of utility methods to do Collection Difference

Description

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

Method

int[]computeDifferenceIndices(Collection smallCollection, Collection bigCollection)
Computes the array of element indices which where added to a collection.
List<Integer> addedIndices = new ArrayList<>();
int index = 0;
for (Iterator<?> ite = bigCollection.iterator(); ite.hasNext(); index++) {
    if (smallCollection == null || !smallCollection.contains(ite.next())) {
        if (smallCollection == null) {
            ite.next();
        addedIndices.add(index);
...
Collectiondiff(Collection c1, Collection c2)
diff
if (c1 == null || c1.size() == 0 || c2 == null || c2.size() == 0) {
    return c1;
Collection<T> difference = new ArrayList<T>();
for (T item : c1) {
    if (!c2.contains(item)) {
        difference.add(item);
return difference;
ListdiffColls(Collection oldColl, Collection newColl)
diff Colls
List<Object[]> ops = new ArrayList<Object[]>();
for (Object newElt : newColl) {
    if (!oldColl.contains(newElt))
        ops.add(new Object[] { 1, null, newElt });
for (Object oldElt : oldColl) {
    if (!newColl.contains(oldElt))
        ops.add(new Object[] { -1, null, oldElt });
...
Collectiondifference(Collection set1, Collection set2)
difference
List<E> differenceCopy = new ArrayList<E>();
differenceCopy.addAll(set1);
differenceCopy.removeAll(set2);
return differenceCopy;
Collectiondifference(Collection collection1, Collection result, Collection collection2)
Stores the differences of two collections in a result collection.
for (Iterator<K> iterator = collection1.iterator(); iterator.hasNext();) {
    K item = iterator.next();
    if (!collection2.contains(item)) {
        result.add(item);
return result;
Collectiondifference(Collection a, Collection b)
Difference of two collections
return null;
Collectiondifference(final Collection c1, final Collection c2)
difference
return union(leftDifference(c1, c2), rightDifference(c1, c2));
Listdifference(final Collection c1, final Collection c2)
Returns a such that a exists in c1 but not in c2.
if (c1 == null || c1.size() == 0) {
    return new ArrayList<>(0);
if (c2 == null || c2.size() == 0) {
    return new ArrayList<>(c1);
final List<T> difference = new ArrayList<>();
for (final T current : c1) {
...
BooleandifferentNull(Collection collection)
different Null
return collection != null;
List[]getIntersectAndDiffs(Collection a, Collection b, Comparator comparator)
Returns a three-element array of mutable List s:
    the intersection of a and b
  1. the a - b difference
  2. the b - a difference
int aSize = a.size();
List<T> aDiff = new ArrayList<T>(aSize);
aDiff.addAll(a);
int bSize = b.size();
List<T> bDiff = new ArrayList<T>(bSize);
bDiff.addAll(b);
if (comparator != null) {
    Collections.sort(aDiff, comparator);
...