navy navy - 15 days ago 7
Java Question

remove one Collection elements from other

Hi i have two Collection of SomeType a1,a2 and want to remove all the elements of a2 from a1.

Please suggestion which type of Collection i need to use :


  1. ArrayList

  2. LinkList

  3. some other ?.



Is there any library for this ?

Answer

Thanks to all. After reading your response i created a Filter class like this :

public class Filter {

    public <T> Set<T> filter(Set<T> all, Set<T> blocked) {
        for (T t : all) {
            if(blocked.contains(t)) {
                all.remove(t);
            }
        }
        return all;
    }
}