jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes .equals ( ) and == 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 ".equals ( ) and == " Watch ".equals ( ) and == " New topic

.equals ( ) and ==

Himabindu Devulapalli

Joined: Apr 05, 2000
Posts: 18
Hi Java gurus.,
When should I use .equals() and == in Java.
Is .equals() used for String objects alone ?
Thanks in adv...
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
== 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!
SaiRam NageshKumar

Joined: Apr 06, 2000
Posts: 21
Just execute the following to clear ur doubt. If u're not cleared dig it again. Try with & without the commented(//) statement.

I agree. Here's the link: http://aspose.com/file-tools
subject: .equals ( ) and ==
jQuery in Action, 3rd edition