我有两个列表如下
List<String> pathNames = Lists.newArrayList("/state", "/country", "/country/name");
List<String> newPaths = Lists.newArrayList("/country/name");
我有正常的每个Java代码迭代两个列表中找到匹配,并返回boolean值,如下
if(CollectionUtils.isNotEmpty(pathNames)) {
for (String path : newPaths) {
for (String reqPath: pathNames) {
if(FilenameUtils.wildcardMatch(path, reqPath)) {
return true;
}
}
}
}
但我想重构和做Java8同样,任何帮助可大加赞赏。
您可以使用两个列表和呼叫流管道anyMatch
:
return CollectionUtils.isNotEmpty(pathNames) &&
newPaths.stream().anyMatch(np ->
pathNames.stream().anyMatch(pn -> FilenameUtils.wildcardMatch(np, pn)));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句