I want a brief definition about the equals() , \"==\" and hashCode(). If i run following code means the output will be \"true false 2420395 2420395\". But i had understand that
.equals()
compares the actual content of the string.
The "==" operator compares if the two objects are the same reference in memory. If you were to do str = str1;
, then the double-equals operator would return true
because they point to the same reference in memory.
hashCode()
returns a hash of the object in an arbitrary manner. The value returned will always be unique as long as the method is not overridden in some way. If .equals()
returns true, the hash code should be the same.