Skip to content

Commit a9afce1

Browse files
committed
exp4
1 parent f01dde3 commit a9afce1

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

labsheets/Exp3_M1.docx

22.6 KB
Binary file not shown.

labsheets/Exp4_M1.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.*;
2+
class Student{
3+
int rno;
4+
String name;
5+
int age;
6+
float fees;
7+
8+
public Student(int rno, String name, int age, float fees) {
9+
super();
10+
this.rno = rno;
11+
this.name = name;
12+
this.age = age;
13+
this.fees = fees;
14+
}
15+
16+
17+
@Override
18+
public String toString() {
19+
return rno + " " + name + " " + age + " " + fees;
20+
}
21+
}
22+
class Exp4 {
23+
public static void main(String[] args) {
24+
List <Student> s = new <Student>ArrayList();
25+
s.add(new Student(1,"abc",20,20000.00f));
26+
s.add(new Student(2,"xyz",15,15000.00f));
27+
s.add(new Student(3,"def",10,10000.00f));
28+
29+
System.out.println("Sorting on the basis of name...");
30+
31+
// implementing lambda expression
32+
Collections.sort(s,(s1,s2)->{return s1.name.compareTo(s2.name);});
33+
for(Student l:s){
34+
System.out.println(l);
35+
}
36+
System.out.println("Sorting by age");
37+
38+
Collections.sort(s,(s1,s2)-> s1.age - s2.age);
39+
s.forEach((l)->System.out.println(l));
40+
41+
System.out.println("Sorting by Fees");
42+
43+
Collections.sort(s,(s1,s2)-> (int)s1.fees - (int)s2.fees);
44+
s.forEach((l)->System.out.println(l));
45+
46+
}
47+
}

0 commit comments

Comments
 (0)