jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt about equals vs == Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt about equals vs ==" Watch "doubt about equals vs ==" New topic

doubt about equals vs ==

NarendraMohan Prasad

Joined: Oct 31, 2004
Posts: 4
I've written the following code for the test
I want reason for the difference between ==
and .equals.
why == is giving true for the "Test1"

(Changed title to be meaningful)
[ June 06, 2007: Message edited by: Barry Gaunt ]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
Hi Narendra,

This sort of question has been discussed hundreds of times. If you use
the search facility of JavaRanch, you will find so many interesting discussion
on this.

Hint: When you use new operator to create String object, object is created
at run time. Without using "new" you call compile time created String object.
Objects created with "new", gives false result when you use == to compare
them even if the content is same. Because == compares references of the


ram shah

Joined: Jun 02, 2007
Posts: 28

pls go through the link mentioned above......your doubt would be clear.
I agree. Here's the link: http://aspose.com/file-tools
subject: doubt about equals vs ==
It's not a secret anymore!