Digital :
I have two lists as below
List<String> pathNames = Lists.newArrayList("/state", "/country", "/country/name");
List<String> newPaths = Lists.newArrayList("/country/name");
I have normal for each java code to iterate two lists to find a match and return boolean as below
if(CollectionUtils.isNotEmpty(pathNames)) {
for (String path : newPaths) {
for (String reqPath: pathNames) {
if(FilenameUtils.wildcardMatch(path, reqPath)) {
return true;
}
}
}
}
But I want to refactor and do the same in Java8, any help can be much appreciated.
ernest_k :
You can use a stream pipeline on both lists and call anyMatch
:
return CollectionUtils.isNotEmpty(pathNames) &&
newPaths.stream().anyMatch(np ->
pathNames.stream().anyMatch(pn -> FilenameUtils.wildcardMatch(np, pn)));
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=389437&siteId=1