11package com .winterbe .java8 ;
22
3- import java .util .ArrayList ;
3+ import java .util .Arrays ;
44import java .util .List ;
55import java .util .stream .Stream ;
66
1212public class Streams5 {
1313
1414 public static void main (String [] args ) {
15- List <String > stringCollection = new ArrayList <>();
16- stringCollection .add ("ddd2" );
17- stringCollection .add ("aaa2" );
18- stringCollection .add ("bbb1" );
19- stringCollection .add ("bbb3" );
20- stringCollection .add ("ccc" );
15+ List <String > strings =
16+ Arrays .asList ("d2" , "a2" , "b1" , "b3" , "c" );
2117
22- // test1(stringCollection );
23- // test2(stringCollection );
24- // test3(stringCollection );
25- // test4(stringCollection );
26- test5 (stringCollection );
27- // test6(stringCollection );
28- // test7(stringCollection );
18+ // test1(strings );
19+ // test2(strings );
20+ // test3(strings );
21+ // test4(strings );
22+ // test5(strings );
23+ test6 (strings );
24+ // test7(strings );
2925 }
3026
3127 // stream has already been operated upon or closed
@@ -42,15 +38,14 @@ private static void test7(List<String> stringCollection) {
4238 private static void test6 (List <String > stringCollection ) {
4339 stringCollection
4440 .stream ()
45- .filter (s -> {
46- System .out .println ("filter: " + s );
47- return s .startsWith ("a" );
48- })
4941 .map (s -> {
50- System .out .println ("map: " + s );
42+ System .out .println ("map: " + s );
5143 return s .toUpperCase ();
5244 })
53- .anyMatch (s -> s .startsWith ("A" ));
45+ .anyMatch (s -> {
46+ System .out .println ("anyMatch: " + s );
47+ return s .startsWith ("A" );
48+ });
5449 }
5550
5651 private static void test5 (List <String > stringCollection ) {
0 commit comments