Selenium - Java8 - Streams, Filters, Collectors examples
Code:
package sfcl;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class streamFilterCollectorList {
public static void main(String[] args) {
List<String> nmaes = Arrays.asList("Anderson", "Paul", "Ahamed", "Ram");
// change list to stream
List<String> output = nmaes.stream()
// we are filtering out ram
.filter(line -> !"Ram".equals(line))
// Stores the output and changes streams to a List
.collect(Collectors.toList());
Iterable<String> result;
output.forEach(System.out::println);
}
}
OutPut:
No comments:
Post a Comment