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.
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
"Chararcter by character compatison " - it is simple

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




 
0
gudii9Author Commented:
does it different from absolute comparison. what is shallow comparison. What are different kinds of comparisons available. Please advise
0
for_yanCommented:


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.


0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

gudii9Author Commented:
hashcode() just compares the reference variables of the object reference right unlike each and every character. please advise
0
for_yanCommented:
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.
0
for_yanCommented:
Read these excerpts for Java API for hashcode()
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#hashCode%28%29
and for equals()
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals%28java.lang.Object%29


You'll first see my point that hashcode() is a function of just one object, so by itself it does not compare  two objects, like equals(Object o), which in general situation uses two objects - the object on which this method is running and the object which is supplied by the argument

Another distiction that hashcode() returns integer
and equals() returns boolean

Otherwise there are of course some things to think about in these
descriptions

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.