We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I think it's better to use the primitive specializations of Comparator.comparing() for primitive keys, that is comparingDouble() for the CGPA and comparingInt() for the ID. This way we can avoid unneccessary boxing.
My next thaught: "Consider implementing Comparable" (check Joshua Bloch's "Effective Java")?
Finally, using Java 8 we could even read the input data and generate a sorted list in one go:
Java Sort
You are viewing a single comment's thread. Return to all comments →
+1 for using Java 8 features.
I think it's better to use the primitive specializations of
Comparator.comparing()
for primitive keys, that iscomparingDouble()
for the CGPA andcomparingInt()
for the ID. This way we can avoid unneccessary boxing.My next thaught: "Consider implementing
Comparable
" (check Joshua Bloch's "Effective Java")?Finally, using Java 8 we could even read the input data and generate a sorted list in one go: