wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp ( == vs .equals() ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scjp ( == vs .equals() )" Watch "scjp ( == vs .equals() )" New topic

scjp ( == vs .equals() )

Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
some one plz explain me the difference between == operator and equals op for the strings clearly
thanking you
[ Jess added a more descriptive title ]
[ January 22, 2004: Message edited by: Jessica Sant ]
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
For Strings the == operator compares the object's memory addresses, if they are the same address, they are the same object.
The equals() method compares the contents of the Strings, so:

[ January 22, 2004: Message edited by: Ray Stojonic ]
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
the == operator looks for reference locations where as the equals looks at the actual object.

So the == operator will look for the memory address and the equals() will look for the actual objects data/values.
does this explain it easier?

How simple does it have to be???
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

Kumar -
Try giving your questions a more descriptive title than "scpj" -- that way people can understand more about what your asking and also tell the difference between your questions.
I've added a bit of description in order to help get you started.
good luck with your studying!

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
I agree. Here's the link: http://aspose.com/file-tools
subject: scjp ( == vs .equals() )
It's not a secret anymore!