File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
src/test/java/com/amigoscode/examples Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .amigoscode .examples ;
2+
3+ import com .amigoscode .beans .Person ;
4+ import com .amigoscode .mockdata .MockData ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ import java .io .IOException ;
8+ import java .util .ArrayList ;
9+ import java .util .List ;
10+ import java .util .stream .Collectors ;
11+
12+ public class UnderstandingStreams {
13+
14+ @ Test
15+ void collect () throws IOException {
16+ List <String > emails = MockData .getPeople ()
17+ .stream ()
18+ .map (Person ::getEmail )
19+ .collect (
20+ ArrayList ::new ,
21+ ArrayList ::add ,
22+ ArrayList ::addAll
23+ );
24+ emails .forEach (System .out ::println );
25+ }
26+
27+ @ Test
28+ public void lazy () throws Exception {
29+ System .out .println (
30+ MockData .getCars ()
31+ .stream ()
32+ .filter (car -> {
33+ System .out .println ("filter car " + car );
34+ return car .getPrice () < 10000 ;
35+ })
36+ .map (car -> {
37+ System .out .println ("mapping car " + car );
38+ return car .getPrice ();
39+ })
40+ .map (price -> {
41+ System .out .println ("mapping price " + price );
42+ return price + (price * .14 );
43+ })
44+ .collect (Collectors .toList ())
45+ );
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments