forked from Apress/functional-interfaces-in-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSect7_Ex1.java
More file actions
29 lines (28 loc) · 817 Bytes
/
Sect7_Ex1.java
File metadata and controls
29 lines (28 loc) · 817 Bytes
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
package chapter12;
import java.util.*;
import java.util.stream.Stream;
import chapter10.Student;
class Class
{
String subject;
Collection<Student> students;
public Class(String su, Student... st)
{
subject = su;
students = Arrays.asList(st);
}
}
public class Sect7_Ex1
{
public static void main(String[] args)
{
Stream.of(new Class("Biology",
new Student("Joe" ,1001,3.81),
new Student("Mary",1002,3.91)),
new Class("Physics",
new Student("Kalpana",1003,3.61),
new Student("Javier" ,1004,3.71))) // Stream<Class>
.flatMap(x -> x.students.stream()) // Stream<Student>
.forEach(x -> System.out.println(x));
}
}