-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamsExample.java
More file actions
39 lines (29 loc) · 1.02 KB
/
Copy pathStreamsExample.java
File metadata and controls
39 lines (29 loc) · 1.02 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
package stream9;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import streamsData.StudentDataBase;
import streamsData.Student;
public class StreamsExample {
public static void main(String[] args) {
Predicate<Student> gradePredicate = student -> student.getGradeLevel() >= 3;
Predicate<Student> gpaPredicate = student -> student.getGpa() >= 3.9;
Map<String, List<String>> studentInfo = StudentDataBase.getAllStudents().stream().filter(gradePredicate)
.filter(gpaPredicate).collect(Collectors.toMap(Student::getName, Student::getActivities));
System.out.println(studentInfo);
String[] names = { "Sam", "Pamela", "Dave", "Pascal", "Erik" };
List<String> l = new ArrayList<String>();
l.add("1");
l.add("2");
l.add("3");
l.add("4");
l.add("5");
l.add("6");
IntStream.range(0, l.size()).forEach(index -> {
System.out.println(index + " " + l.get(index));
});
}
}