-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.java
More file actions
41 lines (30 loc) · 833 Bytes
/
Copy pathDemo.java
File metadata and controls
41 lines (30 loc) · 833 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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
class Student
{
int age;
String name;
public Student(int age, String name) {
this.age = age;
this.name = name;
}
public String toString() {
return "student [age=" + age + ", name=" + name + "]";
}
}
public class Demo {
public static void main(String[] args) {
Comparator<Student> com = (i, j) -> i.age > j.age ? 1 : -1;
List<Student> studs = new ArrayList<>();
studs.add(new Student(21,"Navin"));
studs.add(new Student(12,"John"));
studs.add(new Student(18,"Parul"));
studs.add(new Student(20,"Kiran"));
Collections.sort(studs, com);
for(Student s: studs){
System.out.println(s);
}
}
}