开发者

Remove objects from a java set

How do i remove all the objects from one set, that exist also in an other set. for exaple:

开发者_如何学Go
SET 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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜