Java Collection Remove removeAllFromCollection(Collection collection, Collection toRemove)

Here you can find the source of removeAllFromCollection(Collection collection, Collection toRemove)

Description

Removes each element in given collection one by one from specified collection.

License

Open Source License

Parameter

Parameter Description
collection collection to remove from.
toRemove collection containing elements to remove.

Return

True if original collection is changed, false otherwise.

Declaration

public static boolean removeAllFromCollection(Collection collection,
        Collection toRemove) 

Method Source Code

//package com.java2s;
import java.util.Collection;

public class Main {
    /**//from   ww  w. ja v a  2 s  .  c  om
     * Removes each element in given collection one by one from specified collection.
     *
     * @param collection collection to remove from.
     * @param toRemove collection containing elements to remove.
     * @return True if original collection is changed, false otherwise.
     */
    public static boolean removeAllFromCollection(Collection collection,
            Collection toRemove) {
        boolean changed = false;

        // loop to remove each of element
        for (Object obj : toRemove) {
            changed |= collection.remove(obj);
        }

        return changed;
    }
}

Related

  1. removeAll(Collection source, Collection remove)
  2. removeAll(final Collection c, final Object... array)
  3. removeAll(final Collection collection, final Collection remove)
  4. removeAll(final Collection collection, final T... objects)
  5. removeAllElements(Collection data, T value)
  6. removeAllFromSet(AbstractSet collection, Collection toRemove)
  7. removeAny(Collection collection)
  8. removeArrayMarkerFromCollectionToString(Collection col)
  9. removeArrayToCollection(T[] array, Collection collection)