File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes toString method class - question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

toString method class - question

Abid Ramay
Ranch Hand

Joined: Apr 06, 2013
Posts: 43
Hi there

how do you read Java API documentation? e.g. below toString() method class .. how do i read this information ?


public String toString()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

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())

a string representation of the object.

thanks for you help.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46337
The API documentation is not written so as to be easy for beginners to read, but that particular example is clear. What are you having difficulty with?
Joel Christophel
Ranch Hand

Joined: Apr 20, 2011
Posts: 249

Abid Ramay wrote:
public String toString()

public means that the method is visible and can be called from other objects of other types. String tells you that the method's return type (output) is a String. The empty parenthesis in toString() tell you that you don't have to pass in anything to the method.

Abid Ramay wrote:
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object.

This is the summary of the method's function. This also tells you that the toString() can be used on any object (since it is defined in the Object class).

The best way to find out exactly how a method works, however, is to try it out.
Try something like:

And try different things. For example, using the toString method on objects like Integer or Boolean simply returns their values as a String.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

the above is

name of the method

the method's signiature

a description of what it does.

what it returns.

Which part doesn't make sense?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: toString method class - question
It's not a secret anymore!