• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String again

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");

y it prints equal?

does toString() method returns a new object?
please clarify
Thanks in adavnce
sunil.s
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
yes toString() , whose return type is Object always returns
a new object.Hence the result.
regds
NM,SCJP
 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello mukherjee,
since it returns a new object shouldn,t it print not equal bcos one is in the pool and other in heap.
plz clarify if iam wrong
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since it is retruning it self ( i.e tostring ) above will print equal.
reproduced from API
toString
public String toString()
This object (which is already a string!) is itself returned.
Overrides:
toString in class Object
Returns:
the string itself.
Sasi
 
reply
    Bookmark Topic Watch Topic
  • New Topic