What if you have a specific scenario where you want to first sort by rank and then alphabetically if the ranks are same?
Any number of Comparator classes can be created to sort them differently as shown below. import java.util.Comparator; public class JavaTechnologyComparator implements Comparator<JavaTechnology> { @Override public int compare(JavaTechnology t1, JavaTechnology t2) { //handle null values here Integer rank1 = t1.getRank(); Integer rank2 = t2.getRank(); int rankVal = rank1.compareTo(rank2); int nameVal = t1.getName().toLowerCase().compareTo(t2.getName().toLowerCase()); … Read more