File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
src/main/java/lambdasinaction/chap7 Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ package lambdasinaction .chap7 ;
2+
3+ /**
4+ * Created by raoul-gabrielurma on 16/05/2014.
5+ */
6+ import java .util .*;
7+
8+ public class Debugging {
9+ public static void main (String [] args ) {
10+ List <Point > points = Arrays .asList (new Point (12 , 2 ), null );
11+ points .stream ().map (p -> p .getX ()).forEach (System .out ::println );
12+ }
13+
14+
15+ private static class Point {
16+ private int x ;
17+ private int y ;
18+
19+ private Point (int x , int y ) {
20+ this .x = x ;
21+ this .y = y ;
22+ }
23+
24+ public int getX () {
25+ return x ;
26+ }
27+
28+ public void setX (int x ) {
29+ this .x = x ;
30+ }
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ package lambdasinaction .chap7 ;
2+
3+ import java .util .List ;
4+ import java .util .stream .Stream ;
5+
6+ import static java .util .stream .Collectors .toList ;
7+
8+ /**
9+ * Created by raoul-gabrielurma on 16/05/2014.
10+ */
11+ public class Peek {
12+
13+ public static void main (String [] args ) {
14+
15+ List <Integer > result = Stream .of (2 , 3 , 4 , 5 )
16+ .peek (x -> System .out .println ("taking from stream: " + x )).map (x -> x + 17 )
17+ .peek (x -> System .out .println ("after map: " + x )).filter (x -> x % 2 == 0 )
18+ .peek (x -> System .out .println ("after filter: " + x )).limit (3 )
19+ .peek (x -> System .out .println ("after limit: " + x )).collect (toList ());
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments