java - functioning of (== ) in terms of hashCode -


string s1="abc";

string s2=new string("abc");

when compare both

s1==s2; return false

and when compare s1.hashcode()==s2.hashcode return true

i know (==) checks reference id's .does returning true in above comparison because above hashcode saved same bucket??please give me explanation

don't forget hash codes primitive integers, , comparing primitives using == compare values, not references (since primitives don't have references)

hence 2 strings having same contents yield same hash code, , comparison via == valid.

the concept of bucket valid when put object hashed collection (e.g. hashset). value of hash code dictates bucket object goes into. hash codes aren't stored.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -