-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamsMapExample.java
More file actions
34 lines (28 loc) · 1.14 KB
/
StreamsMapExample.java
File metadata and controls
34 lines (28 loc) · 1.14 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
package com.learnJava8.streams;
import com.learnJava8.data.Student;
import com.learnJava8.data.StudentDataBase;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class StreamsMapExample {
static List<String> namesList() {
List<String> namesList = StudentDataBase.getAllStudents().stream()// Stream<Student>
// Student as an input, String as the output
.map(Student::getName)// Stream<String>
.map(String::toUpperCase) // Same type, so doing an operation
.collect(Collectors.toList());
return namesList;
}
static Set<String> namesSet() {
Set<String> namesSet = StudentDataBase.getAllStudents().stream()// Stream<Student>
// Student as an input, String as the output
.map(Student::getName)// Stream<String>
.map(String::toUpperCase) // Same type, so doing an operation
.collect(Collectors.toSet());
return namesSet;
}
public static void main(String[] args) {
System.out.println(namesList());
System.out.println(namesSet());
}
}