How to iterate through an HashMap in java

The following is a sample code to iterate through an hashmap in java

 public static void main(String[] args)
    {
        Map<String,Integer> stdMrks = new HashMap<>();
        stdMrks.put("A", 51);
        stdMrks.put("B", 52);
        stdMrks.put("C", 82);
        stdMrks.put("D", 85);
        stdMrks.put("E", 49);
       
        List<String> stds = new ArrayList<>();
       
        Set<String> keys = stdMrks.keySet();
        for(String s:keys)
        {
                Integer value = stdMrks.get(s);
                if(value >=51 && value <=82)
                {
                        stds.add(s);
                }
                       
        }
        System.out.println(stds);
    }
Interview Questions: 

Search