This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "toString()" Watch "toString()" New topic
Author

toString()

Mohit Agarwal
Ranch Hand

Joined: Mar 30, 2004
Posts: 88
Long l=new Long("127");
l.toString()==l.toString()//gives false.

When ever toString() method is called on a object a new string object is created or i m missing some thing.


Mohit Agarwal
Would be SCJP.

"The will to win is worthless if you do not have the will to prepare"
Poonam Advani
Ranch Hand

Joined: Aug 25, 2004
Posts: 38
Ya,
u r right !
l.toString()==l.toString() creates two new strings where in case the == returns false.

Shruti
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
If == returns false when comparing two objects then they are different objects. So the answer is yes; Long.toString() returns a new unique String instance each time its called.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: toString()