This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Object.toString() is used for objects.
String.valueOf(primitive) for primitives.
String.valueOf(object) returns "null" if the object is null else object.toString()
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Arun raghvan
Ranch Hand
Joined: Aug 22, 2010
Posts: 75
posted
0
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
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.
Joanne
Arun raghvan
Ranch Hand
Joined: Aug 22, 2010
Posts: 75
posted
0
Got in Snap !!
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Difference between valueOf()Method and toString()Method