You are viewing a single comment's thread. Return to all comments →
Comparator<Student> score = new Comparator<Student>() { public int compare(Student a, Student b){ if(a.getCgpa() < b.getCgpa()) return 1; else if(a.getCgpa() > b.getCgpa()) return -1; else if(a.getFname().compareTo(b.getFname()) > 0) return 1; else if(a.getFname().compareTo(b.getFname()) == 0 && a.getId()<b.getCgpa()) return 1; else return -1; } }; Collections.sort(studentList, score); for(Student st: studentList){ System.out.println(st.getFname()); }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Java Sort
You are viewing a single comment's thread. Return to all comments →