I need to implement a Map which must have a custom hash (returns an integer- year + car model number) and it also has to be sorted in decreasing order. If I use a TreeMap, I cannot make a custom hash, and if I use a HashMap, I cannot order it. How can I use both? I tried making a TreeMap with a custom comparator for decreasing order but it ignores my overriding of the hashCode and adds elements that should be in different places on the same place, even though their hashcodes are different. How can I solve this?
class MyComparator implements Comparator<Integer> {
public int compare(Integer a, Integer b) {
if (a < b) {
return 1;
}
return 0;
}
}