Java Collection Subtract subtractCollections(Collection collection1, Collection collection2)

Here you can find the source of subtractCollections(Collection collection1, Collection collection2)

Description

Returns all items in collection1 that are not in collection2

License

Open Source License

Declaration

public static <T> Collection<T> subtractCollections(Collection<? extends T> collection1,
        Collection<? extends T> collection2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from  w w w. j a v a2s . co m*/
     * Returns all items in collection1 that are not in collection2
     */
    public static <T> Collection<T> subtractCollections(Collection<? extends T> collection1,
            Collection<? extends T> collection2) {
        Collection<T> result = new ArrayList<T>(collection1);
        result.removeAll(collection2);
        return result;
    }
}

Related

  1. subtract(Collection l1, Collection l2)
  2. subtract(final Collection a, final Collection b)
  3. subtract(final Collection a, final Collection b)
  4. subtract(final Collection a, final Collection b)
  5. subtract(final Collection a, final Collection b)