stream().filter java 8 code example
Example 1: java stream filter
List<String> result = lines.stream()
.filter(line -> "theLineIWant".equals(line))
.collect(Collectors.toList());
Example 2: java stream().filter()
NowJava8.java
package com.ricky.java8;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class NowJava8 {
public static void main(String[] args) {
List<String> lines = Arrays.asList("spring", "node", "ricky");
List<String> result = lines.stream()
.filter(line -> !"ricky".equals(line))
.collect(Collectors.toList());
result.forEach(System.out::println);
}
}12345678910111213141516171819202122