-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaugust8.java
81 lines (72 loc) · 1.63 KB
/
august8.java
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
package August;
import java.util.List;
import java.util.stream.Collectors;
public class august8 {
public static void main(String[] args)
{
List<ClassRoom> cr = List.of(
new ClassRoom("Ram Shrma", 15, "Mathematics"),
new ClassRoom("Krishna Shrma", 45, "Physics"),
new ClassRoom("Rahul Pandit", 22, "Chemistry"),
new ClassRoom("Samira Joshi", 31, "Computer")
);
List<ClassRoom> abc= cr.stream().filter(i ->i.getRollNo() < 32)
.collect(Collectors.toList());
//System.out.println(abc);
for(int i =0; i<abc.size(); i++)
{
System.out.println(abc.get(i).getRollNo());
System.out.println(abc.get(i).getStuName());
System.out.println(abc.get(i).getSubj());
}
// map and collect
List<String> name=cr.stream().map(x->x.getStuName())
.collect(Collectors.toList());
for( String ap:name) {
System.out.println(ap);
}
//Name and subj
List<String> sn= cr.stream().map(p->p.getStuName()
.concat(" : ")
.concat(p.getSubj()))
.collect(Collectors.toList());
for(String sp:sn) {
System.out.println(sp);
}
}
}
class ClassRoom{
private String Stu_Name;
private int Roll_No;
private String Subj;
public ClassRoom(String nm, int no, String sb)
{
this.Stu_Name = nm;
this.Roll_No =no;
this.Subj = sb;
}
public String getStuName()
{
return this.Stu_Name;
}
public void setStuName(String nm)
{
this.Stu_Name = nm;
}
public int getRollNo()
{
return this.Roll_No;
}
public void setRollNo(int no)
{
this.Roll_No = no;
}
public String getSubj()
{
return this.Subj;
}
public void setSubj(String sb)
{
this.Subj = sb;
}
}