Java Collection Remove removed(Collection a, Collection b)

Here you can find the source of removed(Collection a, Collection b)

Description

returns the elements added in List a with respect to b

License

Open Source License

Parameter

Parameter Description
a list of element of type T
b list of element of type T

Return

list list of element of type T

Declaration

public static <T> Collection<T> removed(Collection<T> a, Collection<T> b) 

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 a 2s.c o  m*/
     * returns the elements added in List a with respect to b
     * 
     * @param a list of element of type T
     * @param b list of element of type T
     * @return list list of element of type T
     */
    public static <T> Collection<T> removed(Collection<T> a, Collection<T> b) {

        Collection<T> aCopy = new ArrayList<T>(a);
        Collection<T> bCopy = new ArrayList<T>(b);
        Collection<T> added = added(a, b);
        aCopy.removeAll(added);
        bCopy.removeAll(aCopy);
        return bCopy;
    }

    /**
     * returns the elements added in List a with respect to b
     * 
     * @param a list of element of type T
     * @param b list of element of type T
     * @return list list of element of type T
     */
    public static <T> Collection<T> added(Collection<T> a, Collection<T> b) {

        Collection<T> aCopy = new ArrayList<T>(a);
        Collection<T> bCopy = new ArrayList<T>(b);

        aCopy.removeAll(bCopy);
        return aCopy;
    }
}

Related

  1. removeAllFromSet(AbstractSet collection, Collection toRemove)
  2. removeAny(Collection collection)
  3. removeArrayMarkerFromCollectionToString(Collection col)
  4. removeArrayToCollection(T[] array, Collection collection)
  5. removed(Collection old, Collection nu)
  6. removeDuplicates(Collection collection)
  7. removeDuplicates(Collection original)
  8. removeDuplicates(Collection p_collection)
  9. removeDuplicates(Collection objects)