I have a method that sorts a HashMap by value. It works by turning the values into a list, sorting the list and matching each value on the list with they key in the HashMap. Here it is:
The problem is that i get a compiler error:Code:public static <E, A> Map<E, A> sortByValue(HashMap<E, A> map)
{
Map<E, A> finalMap = new HashMap<E, A>();
List<E> yourMapKeys = new ArrayList<E>(map.keySet());
List<A> yourMapValues = new ArrayList<A>(map.values());
List<A> sortedList = new ArrayList<A>(yourMapValues);
Collections.sort(sortedList);
int size = sortedList.size();
for (int i=0; i<size; i++) {
finalMap.put(yourMapKeys.get(yourMapValues.indexOf(sortedList.get(i))), sortedList.get(i));
yourMapKeys.remove(yourMapValues.indexOf(sortedList.get(i)));
yourMapValues.remove(yourMapValues.indexOf(sortedList.get(i)));
}
return finalMap;
}
cannot find symbol
symbol : method sort(java.util.List<Integer>)
location: class java.util.Collections
Collections.sort(sortedList);
What is wrong? the API says Collections supports sort(List<T> list) so why the error?

