[英]java streams filter and include
I have a array of words here.我这里有一堆单词。
I want to get all words:我想得到所有的话:
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
我的预期output应该
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.