java - Why I can't compare string after I use simple json library? -


code:

hashmap<string, string> map = new hashmap<>();                         for(object type:entityobj.keyset()){     string notabletype=string.valueof(type);     system.out.println(notabletype);     string object="notabletype";     if(notabletype.equals(object)){         map.put(entity.tostring(), entityobj.get(type).tostring());         system.out.println(map);     } } 

this weird. tested string notabletype string "notabletype" hash values between object , notabletype totally different. 1 -1929035367 , 1 0.

why? how solve problem?

they surely not equal. must have missed white spaces after string. things easy miss out.

trimming string should take care of this.

notabletype.trim().equalsignorecase(object) 

Comments