File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toString()
 
Similar Threads
Reading a String backward
wrapper classes
Strings
Oh jeez, total newbie question.
format() question