• + 0 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()); // }