My function finds if one word is valid from the list of given words in the list on the page. Therefore, when the page contains words, I wrote it as follows: (Simplified version)
private boolean atLeastOneWordIsValidInThePage(Page page, Set<Long> wordIdsToCheck)
Set<Long> wordIds = page.getWords().stream()
.filter(word -> word.isValid())
.map(word->getWordId())
.collect(Collectors.toSet());
return words.stream().anyMatch((o) -> wordIds.contains(o));
Is this the best java 8 practice for writing it?
I want to stop the search when the first match is found.
source
share