Java Utililty Methods Collection Subtract

List of utility methods to do Collection Subtract

Description

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

Method

ArrayListsubtract(Collection l1, Collection l2)
subtract
ArrayList<T> al = new ArrayList<T>();
al.addAll(l1);
for (T item : l2) {
    al.remove(item);
return al;
Collectionsubtract(final Collection a, final Collection b)
Returns a new Collection containing a - b.
ArrayList list = new ArrayList(a);
for (Iterator it = b.iterator(); it.hasNext();) {
    list.remove(it.next());
return list;
Collectionsubtract(final Collection a, final Collection b)
subtract
ArrayList<K> list = new ArrayList<K>(a);
for (Iterator<K> it = b.iterator(); it.hasNext();) {
    list.remove(it.next());
return list;
Listsubtract(final Collection a, final Collection b)
subtract
ArrayList<T> list = new ArrayList<T>(a);
for (Iterator it = b.iterator(); it.hasNext();) {
    list.remove(it.next());
return list;
Listsubtract(final Collection a, final Collection b)
subtract
List<T> list = new ArrayList<T>(a);
for (T element : b) {
    list.remove(element);
return list;
CollectionsubtractCollections(Collection collection1, Collection collection2)
Returns all items in collection1 that are not in collection2
Collection<T> result = new ArrayList<T>(collection1);
result.removeAll(collection2);
return result;