I have a map like this:
Map<String, TC> mapToSort= new HashMap<String, TC>();
the value is a class:
class TC {
private int a;
public TC(int a) {
this.a = a;
}
//getters-setters
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
}
I want to sort this map not by the keys(that would be easy using TreeMap) but by the field "a" variable in the TC class. So elements with highest "a" values should be on top of the mapToSort. Is there any built-in or otherwise elegant solution to achieve this?