aspose file tools*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt about equals vs ==" Watch "doubt about equals vs ==" New topic
Author

doubt about equals vs ==

NarendraMohan Prasad
Greenhorn

Joined: Oct 31, 2004
Posts: 4
I've written the following code for the test
I want reason for the difference between ==
and .equals.
a
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: 1707
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
objects.


Thanks,


cmbhatt
ram shah
Greenhorn

Joined: Jun 02, 2007
Posts: 28
http://www.javaranch.com/journal/200409/Journal200409.jsp#a1

pls go through the link mentioned above......your doubt would be clear.
 
 
subject: doubt about equals vs ==