-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamExample1.java
More file actions
31 lines (23 loc) · 846 Bytes
/
StreamExample1.java
File metadata and controls
31 lines (23 loc) · 846 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
30
31
package lambda_expression.unit3;
import java.util.Arrays;
import java.util.List;
import lambda_expression.unit1.Person;
public class StreamExample1 {
public static void main(String[] args) {
List<Person> people = Arrays.asList(new Person("Charles", "Dickens", 60), new Person("Lewis", "Carroll", 42),
new Person("Thomas", "Carlyle", 51), new Person("Charlotte", "Bronte", 45),
new Person("Matthew", "Arnold", 39));
people.stream()
.filter(p-> p.getLastName().startsWith("C"))
.forEach(p -> System.out.println(p.getFirstName()));
long count = people.stream()
.filter(p-> p.getLastName().startsWith("D"))
.count();
System.out.println(count);
long count2 = people.parallelStream()
.filter(p-> p.getLastName().startsWith("D"))
.count();
System.out.println(count);
System.out.println(count2);
}
}