Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString()

 
Mohit Agarwal
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya,
u r right !
l.toString()==l.toString() creates two new strings where in case the == returns false.

Shruti
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic