Map<Character, TreeMap<Integer, String>> topElems = new HashMap<Character, TreeMap<Integer, String> > ();
How to set a custom comparator for the TreeMap in the above statement?
Something like:
Map<Character, TreeMap<Integer, String>> topElems = new HashMap<Character, TreeMap<Integer, String> ((x, y) -> y - x) > ();
You're attempting to set the
Comparatorin the type argument, which is invalid syntax. The type arguments only specify the types, they aren't actual instances. What you would need to do is use the correctComparatorfor eachTreeMapyou put into the outerMap:Note you cannot force, via the compiler, that every
TreeMapuse the sameComparatorimplementation.