Java will not and can not extract it from the loop.
Any use of the 'new' keyword will always result in a new object being created.
You would be better off using Double.valueOf()
See the javadoc for Double.valueOf(double):
"Returns a Double instance representing the specified double value. If a new Double instance is not required, this method should generally be used in preference to the constructor Double(double), as this method is likely to yield significantly better space and time performance by caching frequently requested values."
If you used this method it would return the same object every time, thus reducing the number of objects created and increasing performance.
However, using valueOf is still not the answer for you!
valueOf is still a method call, and method calls do not get optimized away. It will call valueOf every iteration of the loop. Look through your method and count the method calls. Right now it is 6, including hasNext and new Double, which is similar to a method call. These will all happen every time, and no java optimization will change that. You are better off refactoring to remove as many method calls as possible from the loop.
Doubleobjects aren't escaping anywhere, so only their contained values are being used. I dare say that the function above should be easy to optimise in the fashion sought by the OP.finalfor local variables has no effect on the bytecode. Certainly, the constancy or not of a variable is for the JIT compiler to determine.finalis mostly an aid to the programmer, to discourage (disallow) them from reassigning a variable (which does help the compiler). But if you actually assign to each local variable once only as a habit, then the presence or absence offinaldoesn't change the bytecode output at all. (The story is different with fields. I do have a policy of making as many fieldsfinalas possible.)