my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ToString method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ToString method" Watch "ToString method" New topic

ToString method

sumaraghavi ragha
Ranch Hand

Joined: Nov 17, 2006
Posts: 118
HI All

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

With an example

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
Wait... let me guess...

To make a String, maybe?

[crossing fingers, hoping I'm right...]
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
API states...
"Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. ..."

SCJP 6 83%
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
and if you see the overriden toString() method in String class, it returns the "this" reference.

SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
I guess one of the core reasons for its existence is String conversion defined in JLS (check out JLS v3 $
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

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

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: ToString method
It's not a secret anymore!