I am trying to sort a map like so (first by value (Integer) then by key (String))
public static Map<String, Integer> sortMap(Map<String, Integer> map) {
List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
// thenComparing( ... ) is causing an error
list.sort(Map.Entry.comparingByValue().thenComparing(Map.Entry.comparingByKey()));
//...
}
I am getting the following error:
Any idea what I am missing ? This was suggested as an alternative in my previous question, but I can't make it work.