1Map -- Sort the map by values
2Write a method that can sort the Map by values
3
4Solution:
5public static Map<String, Integer> sortByValue(Map<String, Integer> map){
6List<Entry<String, Integer>> list = new ArrayList(map.entrySet());
7list.sort(Entry.comparingByValue());
8map = new LinkedHashMap();
9for(Entry<String, Integer> each : list) {
10map.put(each.getKey(), each.getValue());
11}
12return map;
13}