A DESCRIPTION OF THE REQUEST :
When PrintWriter.print(double) or PrintWriter.print(float) are invoked, they call String.valueOf(d) to convert the floating point argument to a string before appending the String's characters to the stream. This creates unnecessary intermediate objects.
StringBuilder uses a much more efficient implementation. It calls FloatingDecimal.appendTo(double, Appendable) which formats the number to a reusable buffer, avoiding unnecessary allocation. PrintWriter implements Appendable, so it ought to be able to use almost exactly the same implementation.
Note that the BinaryToASCIIConverters in FloatingDecimal don't actually handle all Appendable implementors: they special-case StringBuilder and StringBuffer, but it is trivial to also add a special case for PrintWriter here.
JUSTIFICATION :
PrintWriter is unnecessarily slow. Its performance can be easily improved by reusing an existing optimization. (Note that a similar enhancement for char was implemented in Java 1.4; see https://bugs.openjdk.java.net/browse/JDK-4350734)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
pw.print(1.0d) should not allocate garbage objects.
ACTUAL -
pw.print(1.0d) allocates a short-lived String, which immediately becomes garbage. Because of the complexity of formatting floating point numbers, escape analysis is very unlikely to remove this allocation.