Android : Android compare two HashMap Integer and String

on Monday, September 22, 2014


I got two HashMaps with Strings and Integers and both of them carry "20" and 20 When i'm trying to compare them using toString() i always get inequality:



HashMap<String, String> vals = HashMap<String, String>();
HashMap<Integer, Integer> nums = HashMap<Integer, Integer>();

if(nums.get(id).toString() == vals.get("num")) {
Log.i(TAG, "DataBase.updateOrder(): number is the same");
} else {
Log.i(TAG, "DataBase.updateOrder(): number has changed");
}


When i use Integer.valueOf() for String HashMap it works well and they are equal:


if(nums.get(id) == Integer.valueOf(vals.get("num")))


And of course the following record doens't work at all in the way i need:


num.get(id).equals(vals.get("num"))


So the question is why does my first bit of code not work (as i expected)?


0 comments:

Post a Comment