从列表中删除对象 - 包含字符串 - 比较列表 [英] Remove objects from list - contains strings - Comparing the List
问题描述
我的问题是 - 如何通过与第二个列表进行比较来从列表中删除对象.
My question is - How to remove objects from the list by comparing it with the second list.
List1 - 第一个列表包含电子邮件地址.
List2 - 第二个列表包含仅域,格式为@domain.com"等
List1 - The first list contains email addresses.
List2 - The second list contains only domains in the format "@domain.com" etc
我想从第一个列表中删除包含第二个列表中的域的对象(电子邮件).
I would like to remove objects (e-mails) from the first list that contain domains from the second list.
例如:
如果 List1 包含电子邮件地址:email@domain.com",第二个 List2 包含@domain.com" - 那么我想删除这封电子邮件(从 List1)
For example:
If List1 contain email address: "email@domain.com" and second List2 contain "@domain.com" - then I want to remove this email (from List1)
我尝试使用:
List1.removeIf(s -> s.equals (List2));
List1.removeAll(List2);
不幸的是,它没有按照我的意愿过滤我的列表.
Unfortunately, it does not filter my list as I would like.
我将非常感谢您的快速帮助
I will be grateful for your quick help
推荐答案
类似
list1.removeIf(email -> list2.stream().anyMatch(email::endsWith));
应该可以
这篇关于从列表中删除对象 - 包含字符串 - 比较列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!