Sorting in java - Comparable and Comparator example
Comparable and Comparator are interfaces used during sorting of Java collections. Where Comparable is used to define default / natural ordering, Comparator is mainly used to define customized ordering. Here java.util.Collections class comes into picture with 2 important methods, sort(List list) and sort(List list,Comparator c). The best place to read about them is Javadoc. /** * Student class implements comparable interface * and applies comparison logic in compareTo method. * This logic is default logic for ordering students....