Skip to content

Commit 5826adb

Browse files
committed
Challenge 39.
Stream, filter method behaviour.
1 parent 0ff5e51 commit 5826adb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package challenge31_40;
2+
3+
import java.util.List;
4+
5+
/**
6+
*
7+
*/
8+
public class Challenge_39 {
9+
public static void main( String[] args ) {
10+
11+
List<Jedi> jediList = List.of(new Jedi("Luke", 20),
12+
new Jedi("Obiman", 30), new Jedi("QinGon", 40));
13+
14+
jediList.stream()
15+
.filter(jedi -> jedi.name.startsWith("Obi") || jedi.name.startsWith("Luke"))
16+
.filter(jedi -> jedi.name.startsWith("QinGon"))
17+
.map(Jedi::getAge)
18+
.filter(age->age>10)
19+
.forEach(System.out::println);
20+
}
21+
22+
static class Jedi {
23+
private String name;
24+
private int age;
25+
26+
public Jedi( String name, int age ) {
27+
this.name = name;
28+
this.age = age;
29+
}
30+
31+
public int getAge() {
32+
return age;
33+
}
34+
35+
public String getName() {
36+
return name;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)