forked from nrkapri/JavaAdvancedTopics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
49 lines (30 loc) · 783 Bytes
/
Copy pathTest.java
File metadata and controls
49 lines (30 loc) · 783 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package java8;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
NameData n1 = new NameData("A",1);
NameData n2 = new NameData("B",2);
NameData n3 = new NameData("C",3);
NameData n4 = new NameData("D",4);
n1.setChild(n2);
n2.setChild(n3);
n3.setChild(n4);
NameData n5 = new NameData("E",1);
NameData n6 = new NameData("F",2);
NameData n7 = new NameData("G",3);
NameData n8 = new NameData("H",4);
n5.setChild(n6);
n6.setChild(n7);
n7.setChild(n8);
n4.setChild(n5);
printIfAge3(n4);
}
static void printIfAge3(NameData n) {
if(n.getAge()==3)
{
System.out.println(n.toString());
}
if(n.getChild()!=null)
n.getChild().stream().forEach(x->printIfAge3(n));
}
}