gudii9
asked on
Equals method
The equals method applied to a String, however that String was created, performs a character by character comparison.
I was reading above concept from link
http://www.jchq.net/certkey/0502certkey.htm
I was not clear on what it means by 'performs a character by character comparison.'
Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
I was reading above concept from link
http://www.jchq.net/certkey/0502certkey.htm
I was not clear on what it means by 'performs a character by character comparison.'
Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
ASKER
does it different from absolute comparison. what is shallow comparison. What are different kinds of comparisons available. Please advise
This is about shallow and deep equals :
http://lasitheranda.wordpress.com/2009/08/26/shallow-equals-and-deep-equals-using-java-equals-method/
In general I would not go too much into that detail about deep and shallow.
About equals it is good to know how override this method
and that string should be compared only using this method
comparison of strings charcater by character as far as I understand
is as deep as possible - there is no deeper level in the String
which we do not check.
ASKER
hashcode() just compares the reference variables of the object reference right unlike each and every character. please advise
hashcode() does not compare any objects.
hashcode() returns number which is unique for the object. But as opposed to equals it does not return boolean and it does not mention second object.
hashcode() returns number which is unique for the object. But as opposed to equals it does not return boolean and it does not mention second object.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
let's say we compare
strings
"colonel"
and
"column"
we comaper first character in both - they are "c" - indetical
second carcahcter - "o" - identical
third ccharcater "l" - identical
fourth character in "colonel" - it would be "o" , in "column" - it would be "u"
"o" is not the same as "u" - so these two strings are different
if we would have come to the end of the string and all charchters
are matching - those strings would be equal,
that is what method equals(String) performs