I am working in Java code optimization. I\'m unclear about the difference between String.valueOf or the +\"\" sign:
int intVar = 1;
Ask yourself the purpose of the code. Is it to:
It sounds much more like the latter to me... which is why I'd use String.valueOf. Whenever you can make your code read in the same way as you'd describe what you want to achieve, that's a good thing.
Note that this works for all types, and will return "null" when passed a null reference rather than throwing a NullPointerException. If you're using a class (not an int as in this example) and you want it to throw an exception if it's null (e.g. because that represents a bug), call toString on the reference instead.