File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between valueOf()Method and toString()Method

 
Arun raghvan
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
toString() method is used to convert the value into String

valueOf() method which returns the string representation of the corresponding arguments argument.

both are used for same purpose...i am bit confused over here can some someone explain me
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object.toString() is used for objects.
String.valueOf(primitive) for primitives.
String.valueOf(object) returns "null" if the object is null else object.toString()
 
Arun raghvan
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:Object.toString() is used for objects.
String.valueOf(primitive) for primitives.
String.valueOf(object) returns "null" if the object is null else object.toString()


i'm sorry,
not getting .. String class also contains toString() method and valueOf() Method. Both are used to Convert parameter and give it in String Format . So what is the difference
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun raghvan wrote:Both are used to Convert parameter and give it in String Format . So what is the difference


No. Only the String.valueOf method is used to get the String represenation of it's parameter object. The toString method (which all classes have) does not take a parameter.

You can use the String.valueOf method to get the String representation of an object without worrying about null references. If you called toString on a null reference you would get a NullPointerException.
 
Arun raghvan
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got in Snap !!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic