HashMap<Integer, Integer> hmap = new HashMap<>();
hmap.put(1,(int)128);
hmap.put(2,(int)128);
if((hmap.getOrDefault(2, -1)!=hmap.getOrDefault(1, -1)) {
System.out.println("wrong");
}
System.out.println(hmap.get(2)+" "+hmap.get(1));
if(hmap.get(2)==hmap.get(1))
{
System.out.println("wrong2");
}
The above code output on console is wrong In the above case, the output should be wrong2
If I typecast value to int then it shows the output as wrong2
HashMap<Integer, Integer> hmap = new HashMap<>();
hmap.put(1,(int)128);
hmap.put(2,(int)128);
if((int)hmap.getOrDefault(2, -1)!=(int)hmap.getOrDefault(1, -1)) {
System.out.println("wrong");
}
System.out.println(hmap.get(2)+" "+hmap.get(1));
if((int)hmap.get(2)==(int)hmap.get(1))
{
System.out.println("wrong2");
}