You are viewing a single comment's thread. Return to all comments →
The key point is reduce the code of the comparation core. Here is a example which i think a good exercise.
class StudentComparator implements Comparator<Student> { @Override public int compare(Student o1, Student o2) { if (Double.compare(o1.getCgpa(),o2.getCgpa()) == 0 && o1.getFname().compareTo(o2.getFname()) == 0) { return o1.getId() - o2.getId(); }else if( Double.compare(o1.getCgpa(),o2.getCgpa()) == 0 ) { return o1.getFname().compareTo(o2.getFname()); } return Double.compare(o2.getCgpa(), o1.getCgpa()); } }
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 →
The key point is reduce the code of the comparation core. Here is a example which i think a good exercise.