File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes toSting() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "toSting()" Watch "toSting()" New topic


Noman Iqbal
Ranch Hand

Joined: Jun 25, 2001
Posts: 100
I wanna know about that how the toString() method works. I want the answer with complete detail. And also that how to use this function. waiting or reply from any one.
Noman Iqbal.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Well you are going to have a heck of a time getting ANY answer unless you give us some hint about WHAT CLASS you want to know about the toString() method of. There are about 4 zillion classes that have that method, and the answer changes depending on the class.

However as an example:
int i = 1232354345;
String s = Integer.toString(i);
Now s has a string representation of the integer value.
So what class did YOU want to know about?

"JavaRanch, where the deer and the Certified play" - David O'Meara
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Noman,
Since Cindy gave you a great example, I will provide the complete details. Since I tire easily, I will only give details on about 200-300 class (out of Cindy's 4 zillion). Maybe if you keep asking you can start a good collection. If you actually get all 4 zillion you get a new Mercedes (so I heard!).
Complete Details
Happy Reading!
sanno panno

Joined: Jun 25, 2001
Posts: 4
Hi , Noman
In response to your question i want to go on basics, Every class is extended from Object class implictly , and Object class has toString method so every class has a toString method.
While calling toString method using objects of any class returns String representation of that class.
whenever you print an object on console it's imlicit tostring method is called and returned value of toString method is printed on console.

Hope it will work.
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
The toString() method returns a string representation of the object.

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
I agree. Here's the link:
subject: toSting()
It's not a secret anymore!