I want to find if the stream of lines has at least one occurrence of another String
in Set<String>
. I came up with two solutions.
Efficiency, which approach is the best / recommended?
one)
return source.stream().filter(this::streamFilter).count() > 0;
2)
return source.stream().anyMatch(this::streamFilter);
Here's the streamFilter method:
private boolean streamFilter(String str) {
return filterKeywords.contains(str.toLowerCase());
}
filterKeywords: private Set<String> filterKeywords;
Or is there a better approach than this?
source
share