forked from nrkapri/JavaAdvancedTopics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlatMapListOfListTest.java
More file actions
88 lines (60 loc) · 1.32 KB
/
Copy pathFlatMapListOfListTest.java
File metadata and controls
88 lines (60 loc) · 1.32 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package java8;
import java.util.ArrayList;
import java.util.List;
public class FlatMapListOfListTest {
class NameData
{
String name ;
int age;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
List<NameData> child;
List<NameData> getChild()
{
return child;
}
public void setChild(NameData child) {
this.child = new ArrayList();
this.child.add(child);
}
public NameData(String name, int age) {
super();
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "Node [name=" + name + ", age=" + age + "]";
}
}
public static void main(String args[]) {
NameData n1 = new NameData("A",1);
NameData n2 = new NameData("B",2);
NameData n3 = new FlatMapListOfListTest.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);
}
public 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));
}
}