File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toString() method " Watch "toString() method " New topic
Author

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: 3703
    
    5

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: http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html

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 ]

My Blog: Down Home Country Coding with Scott Selikoff
 
Consider Paul's rocket mass heater.
 
subject: toString() method
 
Similar Threads
How to convert StringBuffer to String ?
ToString method
doubt in the advance for loop in java6
= new Object(); is null? Eh?
toString() method...