• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

.equals ( ) and ==

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Java gurus.,
When should I use .equals() and == in Java.
Is .equals() used for String objects alone ?
Thanks in adv...
--Bindu
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
== does shallow comparison. Whereas .equals() does deep comparison only if you override this method. As the .equals() of Object class does the same thing as == does, need to override this method.
boolean equals(Object�obj) Indicates whether some other object is "equal to" this one.
Hope this helps!
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just execute the following to clear ur doubt. If u're not cleared dig it again. Try with & without the commented(//) statement.

reply
    Bookmark Topic Watch Topic
  • New Topic