Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString() method

 
sai prasanna
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
toString() method returns String object is it returns data members or methods
of that object?

thanks in advance
sai prasanna
 
Scott Selikoff
author
Saloon Keeper
Posts: 4015
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic