Explanation

You should replace it with:

d[i] = Double.valueOf(d.length - i);

From its Javadoc:

Deprecated.

It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance.

In general, valueOf is not forced to always return a new instance. It can utilize an internal cache and re-use values created before already, which makes it faster. For example if you create hundreds of 1.0.


Note

Is there a specific reason you are using a Double[] in the first place? If not, go for double[] instead. The primitives are much faster and have less memory overhead, compared to their object wrapper.

Then your code is just:

double[] d = new double[10];
for (int i = 0; i < d.length; i++)
    d[i] = d.length - i;

By the way, you should prefer to never omitt the curly braces. Even if your loop is just one line. This is a very common source for bugs that are hard to find.

Also, your variable naming is not very good. What is d? Try to give it a name that reflects what it actually means. Like ages if it stores person ages, for example. If you do not have something specific, maybe use values. That is already better than just d. Especially since it is plural, so it is clear that it is an array of multiple values.

double[] values = new double[10];
for (int i = 0; i < values.length; i++) {
    values[i] = values.length - i;
}
Answer from Zabuzard on Stack Overflow
Top answer
1 of 2
21

Explanation

You should replace it with:

d[i] = Double.valueOf(d.length - i);

From its Javadoc:

Deprecated.

It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance.

In general, valueOf is not forced to always return a new instance. It can utilize an internal cache and re-use values created before already, which makes it faster. For example if you create hundreds of 1.0.


Note

Is there a specific reason you are using a Double[] in the first place? If not, go for double[] instead. The primitives are much faster and have less memory overhead, compared to their object wrapper.

Then your code is just:

double[] d = new double[10];
for (int i = 0; i < d.length; i++)
    d[i] = d.length - i;

By the way, you should prefer to never omitt the curly braces. Even if your loop is just one line. This is a very common source for bugs that are hard to find.

Also, your variable naming is not very good. What is d? Try to give it a name that reflects what it actually means. Like ages if it stores person ages, for example. If you do not have something specific, maybe use values. That is already better than just d. Especially since it is plural, so it is clear that it is an array of multiple values.

double[] values = new double[10];
for (int i = 0; i < values.length; i++) {
    values[i] = values.length - i;
}
2 of 2
1

From Java 9 constructor(s) method(s) was Deprecated

Deprecated. It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance. Constructs a newly allocated Double object that represents the primitive double argument.

So replace with:

Double.valueOf(d.length - i)
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › lang › Double.html
Double (Java SE 9 & JDK 9 )
Deprecated. It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance. Constructs a newly allocated Double object that represents the primitive double argument.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › Double.html
Double (Java SE 17 & JDK 17)
January 20, 2026 - Deprecated, for removal: This API element is subject to removal in a future version. It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance.
🌐
GitHub
github.com › odpi › egeria › issues › 1712
java.lang deprecations (Int, Double constructors etc) · Issue #1712 · odpi/egeria
java.lang.Integer has been deprecated 15:29:46,870 [WARNING] /Users/jonesn/IdeaProjects/egeria/open-metadata-implementation/user-interfaces/access-services-user-interface/src/main/java/org/odpi/openmetadata/userinterface/accessservices/api/SubjectAreaGlossaryController.java:[153,26] Integer(int) in java.lang.Integer has been deprecated 15:29:46,870 [WARNING] /Users/jonesn/IdeaProjects/egeria/open-metadata-implementation/user-interfaces/access-services-user-interface/src/main/java/org/odpi/openmetadata/userinterface/accessservices/api/SubjectAreaGlossaryController.java:[156,27] Integer(int) in java.lang.Integer has been deprecated · Most of these relate to constructors like Double(double) or Integer(int)ie in java.lang.
🌐
GitHub
github.com › WebFlight › Queue › issues › 6
Double(double) in Double has been deprecated · Issue #6 · ...
New issueCopy link · Closed · ... [deprecation] Double(double) in Double has been deprecated Double exponentialBackOff = new Double(Math.round(base * Math.pow(2, retry))); It is recommended to use Double.valueOf(double) ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.double.-ctor
Double Constructor (Java.Lang) | Microsoft Learn
[<Android.Runtime.Register(".ctor", ... a newly allocated Double object that represents the primitive double argument. This member is deprecated....
🌐
Jsparrow
jsparrow.github.io › rules › inefficient-constructor.html
Replace Inefficient Constructors with valueOf() | jSparrow Documentation
For example new Integer("1") becomes Integer.valueOf("1"). Using this rule saves memory and CPU cycles, as the constructors are not needed in this case. Furthermore, the constructors are deprecated in Java 9, which is an indication that they will eventually be removed from the language altogether. ...
🌐
Apache JIRA
issues.apache.org › jira › browse › SPARK-30676
[SPARK-30676] Eliminate warnings from deprecated constructors of java.lang.Integer and java.lang.Double - ASF JIRA
The constructors of java.lang.Integer and java.lang.Double has been deprecated already, see https://docs.oracle.com/javase/9/docs/api/java/lang/Integer.html.
Find elsewhere
🌐
Java
download.java.net › java › early_access › valhalla › docs › api › java.base › java › lang › Double.html
Double (Java SE 23 & JDK 23 [build 1])
Deprecated, for removal: This API element is subject to removal in a future version. It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance.
🌐
GitHub
github.com › javapathfinder › jpf-core › issues › 47
Deprecated constructor calls with primitive argument - Xlint warnings · Issue #47 · javapathfinder/jpf-core
March 19, 2018 - [javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:247: warning: [deprecation] Byte(byte) in Byte has been deprecated [javac] return new Byte((byte) v); [javac] ^ [javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:249: warning: [deprecation] Character(char) in Character has been deprecated [javac] return new Character((char) v); [javac] ^ [javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:251: warning: [deprecation] Short(short) in Short has been deprecated [javac] return new Short((short) v); [javac] ^ [javac] /home/travis/build/javapathfinder/jpf-core/src/main/gov/nasa/jpf/vm/StackFrame.java:253: warning: [deprecation] Integer(int) in Integer has been deprecated [javac] return new Integer(v); [javac] ^
Published   May 19, 2018
🌐
JetBrains
youtrack.jetbrains.com › issue › IDEA-175693 › Usage-of-obsolete-junit.framework.Assert-method-suggests-deprecated-replacement-for-float-and-double
Jetbrains
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › Double.html
Double (Java SE 11 & JDK 11 )
July 15, 2025 - Deprecated. It is rarely appropriate to use this constructor. The static factory valueOf(double) is generally a better choice, as it is likely to yield significantly better space and time performance. Constructs a newly allocated Double object that represents the primitive double argument.
🌐
Oracle
docs.oracle.com › en › java › javase › 22 › docs › api › › java.base › java › lang › Double.html
Double (Java SE 22 & JDK 22)
July 16, 2024 - Constructs a newly allocated Double object that represents the primitive double argument. ... Deprecated, for removal: This API element is subject to removal in a future version.
🌐
CopyProgramming
copyprogramming.com › howto › alternative-for-deprecated-new-double-double-duplicate
Java: Deprecated New Double(double) - An Alternate Approach [Duplicate]
April 4, 2023 - I'm using Absolute Java, a book ... d[i] = new Double(d.length - i); Subsequently, a cautionary notice was displayed to me. The usage of Double(double) in Double has been deprecated and a warning has been issued....
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › lang › Integer.html
Integer (Java SE 9 & JDK 9 )
Returns the value of this Integer as a double after a widening primitive conversion.
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit2-Using-Objects › topic-2-8-IntegerDouble.html
2.8. Wrapper Classes - Integer and Double — CSAwesome v1
In Java 9 on, this is deprecated which means it’s not the best way to do this anymore, and you should instead just set it equal to a value. The AP CSA Exam covers Java 7 which does allow using the constructor. // in older versions of Java (and on the AP exam) Integer i = new Integer(2); // ...
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8354338
Loading...
(After these classes have permanently become value classes, we can revisit whether to un-deprecate the constructors completely.) Diff of java.lang.Integer is below. Similar changes to be made to all of java.lang.Byte, java.lang.Short, java.lang.Long, java.lang.Float, java.lang.Double, java.lang.Character, and java.lang.Boolean.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-convert-string-to-double-in-java
Java Convert String to Double examples
Java Convert String to double using the constructor of Double class – The constructor Double(String) is deprecated since Java version 9