What's the difference between calling Double.valueOf(String s) and new Double(String s)?
<p>So I've got a String and I want to create a Double object with the String as a value.</p>

<p>I can call</p>

<p><code>Double myDouble = new Double (myString);</code></p>

<p>or I can call</p>

<p><code>Double myDouble = Double.valueOf(myString);</code></p>

<p>Is there a difference? I'm guessing the first guarantees a new object is created on the heap and the second <em>might</em> re-use an existing object.</p>

<p><strong>For extra credit</strong>: the string might be <em>null</em>, in which case I want the Double to be <em>null</em>, but both the above throw a NullPointerException. Is there a way of writing</p>

<p><code>Double myDouble = myString == null ? null : Double.valueOf(myString);</code></p>

<p>in less code?</p>
