I was solving a question on finding the duplicates in an array. I made use of a HashMap. but the getValue() function gave me an error when I included it within an IF condition.
for(Map.Entry m : hm.entrySet())
{  
   if(m.getValue() > 1)
   {
      System.out.println(m.getKey());
   }  
}
however it seems to work fine when I used typecasting
for(Map.Entry m : hm.entrySet())
{ 
    int count = (int)m.getValue();  
    if(count > 1)
    {
        System.out.println(m.getKey());
    }  
}
Why did this happen?
 
     
    