File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Modern-Java-Examples/src/com/learn/streams Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .learn .streams ;
2+
3+ import com .learn .data .Student ;
4+ import com .learn .data .StudentDataBase ;
5+
6+ import java .util .List ;
7+ import java .util .stream .Collectors ;
8+
9+ public class StreamsMapExample {
10+
11+ public static void main (String [] args ) {
12+
13+ System .out .println (namesList ());
14+
15+ System .out .println (upperCaseNamesList ());
16+ }
17+
18+ /**
19+ * <p>
20+ * we want all the names of Student from StudentDataBase and collect it in List.
21+ * </p>
22+ */
23+ public static List <String > namesList () {
24+ return StudentDataBase .getAllStudents ().stream ()
25+ // this Map converting type, taking Student as i/p and return String as output.
26+ .map (Student ::getName )
27+ .collect (Collectors .toList ());
28+ }
29+
30+ /**
31+ * <p>
32+ * we want all the names of Student from StudentDataBase and collect it in List
33+ * and performing uppercase operation on that.
34+ * </p>
35+ * @return
36+ */
37+ public static List <String > upperCaseNamesList () {
38+ return StudentDataBase .getAllStudents ().stream ()
39+ .map (Student ::getName )
40+ // this Map not converting the type, taking String (name) as input and return String as output
41+ .map (String ::toUpperCase )
42+ .collect (Collectors .toList ());
43+ }
44+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ This repository contains the basic & advance level examples related to Java
2424 * [ Streams] ( Modern-Java-Examples/src/com/learn/streams )
2525 * [ Stream Example] ( Modern-Java-Examples/src/com/learn/streams/StreamsExample.java )
2626 * [ Collection vs Stream] ( Modern-Java-Examples/src/com/learn/streams/CollectionVsStream.java )
27+ * [ Streams API Operations]
28+ * [ map()] ( Modern-Java-Examples/src/com/learn/streams/StreamsMapExample.java )
2729
2830
2931
You can’t perform that action at this time.
0 commit comments