Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7b92cf6

Browse files
JavaZakariaemomedalhouma
authored andcommitted
Challenge 20.
finFirst filter method operation on streams.
1 parent ac45cfc commit 7b92cf6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎src/main/java/Challenge_20.java‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.util.List;
2+
3+
/**
4+
*
5+
*/
6+
public class Challenge_20 {
7+
8+
public static void main( String[] args ) {
9+
List<Simpson> list = List.of(new Simpson("Homer", 35),
10+
new Simpson("Margie", 35),
11+
new Simpson("Bart", 10),
12+
new Simpson("Lisa", 8));
13+
14+
list.stream()
15+
.filter(simpson -> simpson.getName().equals("Bart"))
16+
.filter(simpson -> simpson.getAge()>9)
17+
.findFirst();
18+
}
19+
20+
//Homer Margie Bart 10
21+
private static class Simpson {
22+
private String name;
23+
private int age;
24+
25+
public Simpson( String name, int age ) {
26+
this.age=age;
27+
this.name=name;
28+
}
29+
30+
public String getName() {
31+
System.out.println(name);
32+
return name;
33+
}
34+
35+
public int getAge() {
36+
System.out.println(age);
37+
return age;
38+
}
39+
}
40+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /