Get the difference of two collections

 
import java.util.ArrayList;
import java.util.Collection;

public class Utils {

  public static <T> Collection<T> diff(Collection<T> c1, Collection<T> c2) {
    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;
  }
}
  
Home 
  Java Book 
    Runnable examples  

Collection Collection:
  1. Fill a collection
  2. Get the difference of two collections
  3. Get the min value within a collection
  4. Is collection empty, and all of its elements are empty
  5. Make a Collection Read-Only
  6. Make a collection an immutable collection
  7. Sort custom class and user defined Comparator