-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFindFirst.java
More file actions
28 lines (23 loc) · 961 Bytes
/
Copy pathTestFindFirst.java
File metadata and controls
28 lines (23 loc) · 961 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
package stream;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class TestFindFirst {
public static void main(String[] args) {
Student st1 = new Student("Herbert", 'm', 19, 3, 4.5);
Student st2 = new Student("Bryan", 'm', 18, 2, 4.3);
Student st3 = new Student("Helen", 'f', 20, 4, 4.7);
Student st4 = new Student("Josh", 'm', 18, 1, 4.1);
Student st5 = new Student("Mariya", 'f', 21, 5, 4.6);
List<Student> students = new ArrayList<>();
students.add(st1);
students.add(st2);
students.add(st3);
students.add(st4);
students.add(st5);
Student firstStudent = students.stream().map(e ->{e.setName(e.getName().toUpperCase()); return e;})
.filter(e -> e.getSex() == 'f').sorted((x, y) -> x.getAge() - y.getAge())
.findFirst().get();
System.out.println(firstStudent.toString());
}
}