gpt4 book ai didi

Java流,备份流状态

转载 作者:行者123 更新时间:2023-12-02 13:36:03 25 4
gpt4 key购买 nike

在使用 java 流 API 迭代时“备份”集合状态的最简洁方法是什么?

例如,我如何“实现”.backup(allRules)?

ArrayList<String> allRules = new ArrayList<>(); 
Set<String> businessRules = result.getRules().stream()
.map(name -> replace(name, RULES_PACKAGE_NAME, EMPTY))
.backup(allRules)
.filter(name -> !NON_BUSINESS_RULES.contains(name))
.collect(toSet());

最佳答案

只需两步即可完成?

   List<String> allRules = result.getRules().stream()
.map(name -> replace(name, RULES_PACKAGE_NAME, EMPTY))
.collect(Collectors.toList());

Set<String> businessRules = allRules.stream()
.filter(name -> !NON_BUSINESS_RULES.contains(name))
.collect(toSet());

关于Java流,备份流状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43000555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com