This is the code that I have:
Map<Integer,String> map = new HashMap<>();
map.put(23,"Nitin");
map.put(45,"Kapil");
map.put(20, "Sam");
map.put(18,"Adam");
for(Map.Entry m:map.entrySet()){
System.out.println(m.getValue()+":"+m.getValue());
}
But I cannot possible order the data, I need to sort this hash map by value (Name).
Input: Map<Age,Name>
23, Nitin
45, Kapil
20, Sam
18, Adam
Output:
18, Adam
45, Kapil
23, Nitin
20, Sam