results.getTitle-6ren">
gpt4 book ai didi

java - 如何解决 "add all in list cannot be applied to"

转载 作者:行者123 更新时间:2023-12-01 08:46:00 24 4
gpt4 key购买 nike

我有这个方法:

filteredListIn.addAll(Stream.of(listRef)
.filter(results ->
results.getTitle().contains(query.toString().toLowerCase())
));

使用这两个变量:
private List<Results> listRef = new ArrayList<>();
List<Results> filteredListIn = new ArrayList<>();

但我越来越

found for addAll(Stream) filteredListIn.addAll(Stream.of(listRef) ^ method Collection.addAll(Collection) is not applicable (argument mismatch; Stream cannot be converted to Collection) method List.addAll(Collection) is not applicable



有什么问题,我该如何解决?

是否有可能发生这种情况,因为我使用外部库来支持 api 24 下的流?

最佳答案

您必须收集列表中的所有流元素才能将其添加到集合中:

filteredListIn.addAll(listRef.stream()
.filter(results -> results.getTitle().contains(query.toString().toLowerCase()))
.collect(Collectors.toList());

关于java - 如何解决 "add all in list cannot be applied to",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61999285/

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