This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma 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 Java Interview Guide this week in the Jobs Discussion 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
I agree. Here's the link:
subject: Use of toString
It's not a secret anymore!