You are viewing a single comment's thread. Return to all comments →
// by defining user defined comparator we can solve it. it's same as others solved it but passing as argument in streams using lmbda functions.
studentList.stream().sorted((student1,student2)->{int compareCGPA = Double.compare(student2.getCgpa(), student1.getCgpa()); if (compareCGPA != 0) { return compareCGPA; } else { return student1.getFname().compareTo(student2.getFname()); }}).forEach(i->System.out.println(i.getFname())); // for(Student st: studentList){ // System.out.println(st.getFname()); // }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Sort
You are viewing a single comment's thread. Return to all comments →
// by defining user defined comparator we can solve it. it's same as others solved it but passing as argument in streams using lmbda functions.
studentList.stream().sorted((student1,student2)->{int compareCGPA = Double.compare(student2.getCgpa(), student1.getCgpa()); if (compareCGPA != 0) { return compareCGPA; } else { return student1.getFname().compareTo(student2.getFname()); }}).forEach(i->System.out.println(i.getFname())); // for(Student st: studentList){ // System.out.println(st.getFname()); // }