Hope you're doing well. I am having some trouble implementing the comparator method to sort a map by its values. I have written the comparator method, and am now trying to write a method that takes in an unsorted map as input, and uses the comparator implementation to return a sorted Map
. However, there is an error in one of the lines in my code which prevents it from compiling. The code for the sorting method I wrote is given below:
public static HashMap<String,ArrayList<String>>strongSorter(HashMap<String,ArrayList<String>> unsortedMap) {
MapComparator myCompare = new MapComparator(unsortedMap);
HashMap<String,ArrayList<String>> sortedMap = new HashMap<String,ArrayList<String>>(myCompare);
sortedMap.putAll(unsortedMap);
return sortedMap;
}
The error is present in the line where I try and create my sortedMap; Eclipse states that I am not allowed to pass in myCompare as an argument since my inputted arguments must match the inputs to a HashMap<String, ArrayList<String>>
. I don't know how to get around this and would really appreciate any help.
Thanks!