This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Use of toString 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 "Use of toString" Watch "Use of toString" New topic

Use of toString

Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
Hello all.

Can anyone tell me the usage of toString function.And also String toString method.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

default every class you write has object's toString() method which returns the name of the class followed by @hash value.
by overriding the toString method, you can return a more meaningful value to your class, such as attributes and their values

also it is very useful, when you debug by logging a class

in Mkumar

Joined: Sep 08, 2008
Posts: 20
I java, toString() method is used when we need a string representation of an object. It is defined in Object class.
More over, This method can be overridden to customize the String representation of the Object.

Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
Strings toString() returns itself

I no good English.
Nelson Sam
Ranch Hand

Joined: Jun 12, 2010
Posts: 30
Thank you friends
Consider Paul's rocket mass heater.
subject: Use of toString
Similar Threads
why new date() prints date ?????
How to get body-content value in my custom tag?
finding the servlet's base host
Printing object location Not contents