• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

scjp ( == vs .equals() )

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic