Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

toString method class - question

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi there

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


toString

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


Returns:
a string representation of the object.


thanks for you help.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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?
 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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?
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic