So, I have a String, and I want to create a Double object with a string as a value.
I can call
Double myDouble = new Double (myString);
or i can call
Double myDouble = Double.valueOf(myString);
Is there any difference? I assume that the first guarantees the creation of a new object on the heap, and the second can reuse an existing object.
For extra credit : the string may be null, in which case I want Double to be null, but both above have thrown a NullPointerException. Is there any way to write
Double myDouble = myString == null ? null : Double.valueOf(myString);
less code?
java
Rob gilliam
source share