'java streams filter and include

I have a array of words here.

I want to get all words :

  1. more that 5 chars long and
  2. all words starting with a 'i' rregardless of length.

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



Solution 1:[1]

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))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Java Team