Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of toString

 
Nelson Sam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all.

Can anyone tell me the usage of toString function.And also String toString method.
Thanks
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

hth
 
in Mkumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-Manoj
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings toString() returns itself
 
Nelson Sam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you friends
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic