I have an array of words.
I want to get all words that are:
How do I achieve the second criteria?
List<String> words = Arrays.asList("art", "again", "orphanage", "forest", "cat", "bat");
List<String> result = words.stream()
.filter(word -> word.length() > 5)
.collect(Collectors.toList());
result.forEach(word -> System.out.println(word));
My expected output should be art again orphanage forest
Predicate<String> isStartWithA = word -> word.startsWith("a");
Predicate<String> fiveChar = word -> word.length() > 5;
List<String> words=Arrays.asList("art", "again", "orphanage", "forest", "cat", "bat");
List<String> result = words.stream() .filter(isStartWithA.or(fiveChar))
.collect(Collectors.toList());
result.forEach(word -> System.out.println(word))