gpt4 book ai didi

java - 如何根据 map 结果过滤流

转载 作者:行者123 更新时间:2023-12-01 18:45:32 24 4
gpt4 key购买 nike

我有要通过流迭代的对象列表。我需要根据.map方法的结果转换所有不为null的对象。现在,我没有收到错误消息,但是原始列表(incomingRecords)没有被过滤。为了说明我要实现的目标,这是我的伪代码:

List<records> filteredRecords = incomingRecords.stream()
//checkRecords either returns an object or a null -> has been repeatedly tested
.map(record -> checkRecords(anotherList, record))
//filter null records
.filter(record from .map != null)
.collect(Collectors.toList());

最佳答案

List<records> filteredRecords = 
incomingRecords.stream()
.map(record -> checkRecords(anotherList, record))
.filter(record -> record != null)
.collect(Collectors.toList());

关于java - 如何根据 map 结果过滤流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849368/

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