1List<String> result = lines.stream()
2 .filter(line -> "theLineIWant".equals(line))
3 .collect(Collectors.toList());
1NowJava8.java
2package com.ricky.java8;
3
4import java.util.Arrays;
5import java.util.List;
6import java.util.stream.Collectors;
7
8public class NowJava8 {
9
10 public static void main(String[] args) {
11
12 List<String> lines = Arrays.asList("spring", "node", "ricky");
13
14 List<String> result = lines.stream() // convert list to stream
15 .filter(line -> !"ricky".equals(line)) // we dont like ricky
16 .collect(Collectors.toList()); // collect the output and convert streams to a List
17
18 result.forEach(System.out::println); //output : spring, node
19
20 }
21
22}12345678910111213141516171819202122
1public class StreamBuilders
2{
3 public static void main(String[] args)
4 {
5 Stream<Integer> stream = Stream.of( new Integer[]{1,2,3,4,5,6,7,8,9} );
6 stream.forEach(p -> System.out.println(p));
7 }
8}
9