【发布时间】:2019-02-19 13:10:01
【问题描述】:
假设我有一个字符串列表,我想通过过滤字符串列表过滤它们。 对于包含以下内容的列表: “abcd”、“xcfg”、“dfbf”
我会精确列出过滤字符串: “a”,“b”,在类似 filter(i->i.contains(filterStrings) 之后,我想收到“abcd”,“dfbf”的列表, 对于过滤字符串列表: "c", "f" 我想获取 "xcfg" 和 "dfbf" 的列表。
List<String> filteredStrings = filteredStrings.stream()
.filter(i -> i.contains("c") || i.contains("f")) //i want to pass a list of filters here
.collect(Collectors.toList());
除了扩展 lambda 表达式的主体并编写一个带有标志的函数来检查每个过滤器之外,还有其他方法吗?
【问题讨论】:
-
顺便说一下,如果我错了,请纠正我,我假设第二个输出还应该包括
abcd,因为c的存在? -
@nullpointer 是的,你是对的
标签: java filter java-stream