Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ToString method

 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All

Can any one please tell me what is the use of a toString menthod

With an example

Thanks
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait... let me guess...

To make a String, maybe?

[crossing fingers, hoping I'm right...]
 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
API states...
"Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. ..."
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and if you see the overriden toString() method in String class, it returns the "this" reference.
 
Dariusz Kordonski
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess one of the core reasons for its existence is String conversion defined in JLS (check out JLS v3 $15.18.1.1).
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you posting the Same problem again. I had already answered that comprehensively(that's what I think). Here is the link-
use of toString
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic