permaculture playing cards
The moose likes Beginning Java 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 » Java » Beginning Java
Bookmark "toString() method " Watch "toString() method " New topic

toString() method

sai prasanna
Ranch Hand

Joined: May 02, 2005
Posts: 167
hi all
toString() method returns String object is it returns data members or methods
of that object?

thanks in advance
sai prasanna
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

It depends on the type of Object. All Objects inherit a toString() and some have been overridden to return very meaningful representations of the data such as ArrayList class which return lists of elements in an array.

You have to check the API for the class you are working with to determine what toString() does. If the method has not been over-written then refer to the java.lang.Object API for output:

From the website:

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())
[ December 06, 2005: Message edited by: Scott Selikoff ]

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: toString() method
It's not a secret anymore!