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

doubt about equals vs ==

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.javaranch.com/journal/200409/Journal200409.jsp#a1

pls go through the link mentioned above......your doubt would be clear.
 
reply
    Bookmark Topic Watch Topic
  • New Topic