-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamMap.java
More file actions
46 lines (32 loc) · 1.15 KB
/
StreamMap.java
File metadata and controls
46 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package lambda_expression.unit12;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import java.util.List;
import java.util.Set;
import data.Student;
import data.StudentDataBase;
public class StreamMap {
public static void main(String[] args) {
// map() transform one type into other type
List<String> studentList = StudentDataBase.getAllStudents().stream()
.map(Student::getName)
.map(String::toUpperCase).collect(toList());
System.out.println("List :"+studentList);
Set<String> studentSet = StudentDataBase.getAllStudents().stream()
.map(Student::getName)
.map(String::toUpperCase).collect(toSet());
System.out.println("Set :"+studentSet);
List<Student> allStudents = StudentDataBase.getAllStudents();
List<String> studentList2 = allStudents.stream()
.map(Student::getName)
.map(String::toUpperCase).collect(toList());
System.out.println("List :"+allStudents);
System.out.println("List :"+studentList2);
//Check After
/*
StudentDataBase.getAllStudents().stream()
.map(Student::getGpa)
.map(String::toUpperCase).collect(toList());
*/
}
}