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


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.
Who is Participating?
Read these excerpts for Java API for hashcode()
and for equals()

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

"Chararcter by character compatison " - it is simple

let's say we compare





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

gudii9Author Commented:
does it different from absolute comparison. what is shallow comparison. What are different kinds of comparisons available. Please advise
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.


This is about shallow and deep equals :

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.

gudii9Author Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.