*
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
Author

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
shyam
[ 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
kumar,
the == operator looks for reference locations where as the equals looks at the actual object.
e.g:

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?
Davy


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

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
 
GeeCON Prague 2014
 
subject: scjp ( == vs .equals() )