package com.naveen.hashmap;
import java.util.*;
import java.util.Map.Entry;
public class SortBasedonValues {
/**
* @param args
*/
public static void main(String[] args) {
HashMap hm = new HashMap();
hm.put("Naveen", 2);
hm.put("Santosh", 3);
hm.put("Ravi", 4);
hm.put("Pramod", 1);
Set> set = hm.entrySet();
List> list = new ArrayList>(
set);
Collections.sort(list, new Comparator>() {
public int compare(Map.Entry o1,
Map.Entry o2) {
return o2.getValue().compareTo(o1.getValue());
}
});
for (Entry entry : list) {
System.out.println(entry.getValue());
}
}
}