This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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.
 
wood burning stoves
 
subject: toString()
 
Similar Threads
format() question
wrapper classes
Reading a String backward
Strings
Oh jeez, total newbie question.