【问题标题】:Comparison of lists - remove elements列表比较 - 删除元素
【发布时间】:2019-03-22 02:20:46
【问题描述】:

我的问题是 - 如何通过与第二个列表进行比较来从列表中删除对象。


List1 - 第一个列表包含电子邮件地址
List2 - 第二个列表仅包含格式为 "@domain.com"

的域

我想从第一个列表中删除对象(电子邮件),该列表在第二个列表(List2 - 域)上NOT

例如:
如果 List1 包含电子邮件地址“email@domain.com”,而第二个 List2 NOT 包含“@domain.com” - 那么我想删除此电子邮件地址(从列表 1 中)

我知道它可能是重复的帖子:
Remove objects from list - contains strings - Comparing the List
但我不知道如何创建这些答案的否定(!)......

感谢您的快速帮助

【问题讨论】:

    标签: java list removeall remove-if


    【解决方案1】:

    基于your other question 中的accepted answer,您只需将anyMatch 更改为noneMatch

    list1.removeIf(email -> list2.stream().noneMatch(email::endsWith));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 2015-06-11
      • 2016-01-18
      • 1970-01-01
      • 2015-08-01
      相关资源
      最近更新 更多