Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Student {
- private String id;
- private String name;
- private int Batch;
- //Added a class constructor getters and setters
- public static Comparator<Student> studBatch = new Comparator<Student>() {
- public int compare(Student s1, Employee s2) {
- int batch1 = s1.getBatch();
- int batch2 = s2.getBatch();
- //For ascending order
- return (int) (batch1-batch2);
- }};
- }
- ArrayList<Student> stud = new ArrayList<>();
- stud.add(new Student("A01", "John Doe", 101));
- stud.add(new Student("A02", "Mike Gaman", 102));
- Collections.sort(stud, stud.studBatch);
Add Comment
Please, Sign In to add comment