我有 2 个包含字符串的数组列表:
List1 = [no, yes, ok, not]
List2 = [no, but, vote, check]
现在,如何比较 List1 和 List2,如果在 List2 中找到相同的单词,则删除 List1 中的单词。排序后的单词(没有相同的单词)存储在另一个数组列表中。
结果应该是这样的:
List3 = [yes, ok, not]
最佳答案
如果要将结果存储在新列表中,则需要先克隆List1:
ArrayList list3 = (ArrayList) list1.clone();
或
ArrayList list3 = new ArrayList(list1);
然后使用 removeAll :
list3.removeAll(list2);
关于java - 比较字符串ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34940722/