How do i remove all the objects from one set, that exist also in an other set. for exaple:
开发者_如何学GoSET 1 = { a,b,c,d,e,f) |
|---> NEW SET 1= (a,b,d,e}
SET 2 = {c,f) |
I'm not sure what the problem is
set1.removeAll(set2);
code from org.apache.commons.collections.CollectionUtils
public static Collection subtract(final Collection a, final Collection b) {
ArrayList list = new ArrayList( a );
for (Iterator it = b.iterator(); it.hasNext();) {
list.remove(it.next());
}
return list;
}
精彩评论