I am getting null when I am trying to get keys to match with sorted values.
public class Linked_L {
static Map<String, Integer> map = new HashMap<>();
public static void sortbyValue(){
ArrayList<Integer> sortedValues = new ArrayList<>(map.values());
Collections.sort(sortedValues);
for (Integer y: sortedValues)
System.out.println("Key = " +map.get(y) + ", Value = " + y);
}
public static void main(String args[])
{
// putting values in the Map
map.put("Jayant", 80);
map.put("Abhishek", 90);
map.put("Anushka", 80);
map.put("Amit", 75);
map.put("Danish", 40);
// Calling the function to sortbyKey
sortbyValue();
}
Result:
Key = null, Value = 40
Key = null, Value = 75
Key = null, Value = 80
Key = null, Value = 80
Key = null, Value = 90