Hey,
The above posted is correct but I think it needs a modification to the code. I have modified and changed some of the things in the code and the code is now more effective. Here is the code
Code:
Public static void hand(Final String[] args) {
/ / Map Testing
Final Map m = <String, Integer> new HashMap <String, Integer>();
m.could("t1", 1);
m.could("t2", 3);
m.could("t3", 2);
m.could("t4", 3);
/ / Add entries to m a list
Final List <Entry <String, Integer>> entries = new ArrayList <Entry <String, Integer>>(m.entrySet());
/ / Sort the list on the entry value
Collections.fate(entries, new Comparator <Entry <String, Integer>>() {
Public int compares(Final Entry <String, Integer> e1, Final Entry <String, Integer> e2) {
return e1.getValue().compareTo(e2.getValue());
}
});
/ / Display result
for (Final <String, Integer> Entry entry: entries) {
System.out.System.out.println(entry.getKey() + " " + Entry.getValue());
}
}
Bookmarks