Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scjp ( == vs .equals() )

 
Sham Grandhe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic