2014-02-10 38 views
-2

我有两个列表,列表A和列表B,列表A有一些条目也在列表B中。现在我想从列表B中删除这些条目也是在A中,任何人都可以告诉我一种在Java中执行此操作的有效方法吗?删除也是在另一个列表中的列表的条目

+1

只有当你_reveal_你试过不那么有效的方式。 – devnull

+0

迭代并删除它们。 – Maroun

+0

迭代列表d使用remove方法 – Kick

回答

4

使用List#removeAll方法:

从列表中移除所有包含在指定collection(可选操作)中的元素 的。

0
for(int i = 0; i < listA.size(); i++) 
{ 
    int index = -1; 
    for(int j = i; i < listB.size(); j++) 
     if(listA.get(i).equals(listB.get(j)) 
     index = j; 

    if(index >= 0) 
     listB.remove(index); 

} 
相关问题