Converting to String
String class provides us with the method String.valueOf(some stuff) that basically converts "some stuff" into a string..
But we can also concatenate "some stuff" with an empty String ("").
Both these methods result in a String representation of an object(or other data type) so my question is what is the difference between the two, advantages of one over the other, disadvantages of one over the other and which method do you guys usually use when forced to convert something to a String and why??
Re: Converting to String
Indirectly, both of these methods are calling the objects' toString() method.
I normally just call this method to get the object to a string, or alternatively you can directly "add" your object to a string, automatically calling the toString() method and concatenating the strings together. This makes the code easy to read and understand.
Technically, calling the toString() method is the most efficient and uses the least memory, but the performance of all the methods are virtually identical. Note that concatenating strings can become very slow for repeated concatenations of large strings because it does have to create a new character array and copy over both string's to get the new string.
If you have to build large strings, the recommended method would be to use the StringBuilder class.