So why is the Double type so much slower?

Because the value is wrapped inside an object which needs allocation, deallocation, memory management plus getters and setters

Why is it even implemented to allow mathematical operators?

Because autobox is meant to allow you to use such wrappers without worrying about the fact that they are not plain values. Would you prefer not being able to have an ArrayList<Double>? Performance is not always necessary and a drop of 3x-7x of performance according to situations maybe acceptable. Optimization is a requirement which is not always present.

This is true in every situation, using a LinkedList to random access elements could be overkill but this doesn't mean that LinkedList shouldn't be implemented at all. This neither means that using a linked list for few random accesses could interfere with performance so much.

A final note: you should let the VM warm up before benchmarking such things.

Answer from Jack on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
In addition to the eight primitive data types listed above, the Java programming language also provides special support for character strings via the java.lang.String class. Enclosing your character string within double quotes will automatically create a new String object; for example, String s = "this is a string";. String objects are immutable, which means that once created, their values cannot be changed.
Top answer
1 of 3
22

So why is the Double type so much slower?

Because the value is wrapped inside an object which needs allocation, deallocation, memory management plus getters and setters

Why is it even implemented to allow mathematical operators?

Because autobox is meant to allow you to use such wrappers without worrying about the fact that they are not plain values. Would you prefer not being able to have an ArrayList<Double>? Performance is not always necessary and a drop of 3x-7x of performance according to situations maybe acceptable. Optimization is a requirement which is not always present.

This is true in every situation, using a LinkedList to random access elements could be overkill but this doesn't mean that LinkedList shouldn't be implemented at all. This neither means that using a linked list for few random accesses could interfere with performance so much.

A final note: you should let the VM warm up before benchmarking such things.

2 of 3
8

You wouldn't normally use Double, Integer, etc. (Occasionally Integer etc. can be useful to store an 'optional' value - you might want it to be null sometimes. This is less likely with Double because NaN is available for those.)

The reason Double exists is as follows. Java has two main types of value: objects (essentially like C/C++ pointers without the arithmetic), and primitive values (e.g. double). Classes like ArrayList can be defined to accept any Object, which allows users to store String, File or whatever they like in one - but primitive values like double are not covered by such a definition. So classes like Double exist to make it easier for classes like ArrayList to store doubles, without requiring the authors of ArrayList to create special versions for all the primitive types.

🌐
LabEx
labex.io › tutorials › java-how-to-manage-java-primitive-double-types-419119
How to manage Java primitive double types | LabEx
In Java, the double primitive type is a fundamental data type used for representing floating-point numbers with double-precision.
🌐
Programming.Guide
programming.guide › java › double-vs-double.html
Java: Double (class) vs double (primitive) | Programming.Guide
Double is the wrapper type for the primitive type double. Objects of type Double are often referred to as boxed values. The fundamental difference is that Double is a class defined in the standard library, while double is part of the language itself.
🌐
Baeldung
baeldung.com › home › java › core java › introduction to java primitives
Introduction to Java Primitives | Baeldung
January 8, 2024 - Similar to float, we attach the letter D to designate the literal as a double. The simplest primitive data type is boolean. It can contain only two values: true or false. It stores its value in a single bit.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The Double class wraps a value of the primitive type double in an object.
🌐
Rip Tutorial
riptutorial.com › the double primitive
Java Language Tutorial => The double primitive
double d1 = 0d; double d2 = -0d; System.out.println(d1 == d2); // true System.out.println(1d / d1); // Infinity System.out.println(1d / d2); // -Infinity System.out.println(Double.POSITIVE_INFINITY / Double.POSITIVE_INFINITY); // NaN
🌐
TutorialsPoint
tutorialspoint.com › java-program-to-convert-double-to-numeric-primitive-data-types
Java Program to convert Double to numeric primitive data types
Let's say, we have a numeric value of type double and our task is to convert it into other numeric primitive data types. To perform this operation, we require explicit casting as double is the largest primitive datatype available in Java. The process
Find elsewhere
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
As explained in the previous chapter, a variable in Java must be a specified data type: int myNum = 5; // Integer (whole number) float myFloatNum = 5.99f; // Floating point number char myLetter = 'D'; // Character boolean myBool = true; // Boolean String myText = "Hello"; // String · Try it Yourself » · Data types are divided into two groups: Primitive data types - includes byte, short, int, long, float, double, boolean and char ·
🌐
TutorialsPoint
tutorialspoint.com › convert-double-primitive-type-to-a-double-object-in-java
Convert double primitive type to a Double object in Java
public class Demo { public static void main(String args[]) { // double primitive double val = 23.78; // Double object Double ob = new Double(val); System.out.println(ob); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-double-class-java
Java.Lang.Double Class in Java - GeeksforGeeks
July 23, 2025 - Double class is a wrapper class for the primitive type double which contains several methods to effectively deal with a double value like converting it to a string representation, and vice-versa.
🌐
DataCamp
datacamp.com › doc › java › double
double Keyword in Java: Usage & Examples
The double keyword in Java is a primitive data type that represents a double-precision 64-bit IEEE 754 floating point.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.double
Double Class (Java.Lang) | Microsoft Learn
The Double class wraps a value of the primitive type double in an object. [Android.Runtime.Register("java/lang/Double", DoNotGenerateAcw=true)] public sealed class Double : Java.Lang.Number, IConvertible, IDisposable, Java.Interop.IJavaPeerable, ...
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java double – tutorial with programming examples
Java Double - Tutorial With Programming Examples
April 1, 2025 - Java decimal format and big decimal classes are explained here with some frequently asked questions that will help you in understanding the double data type clearly. ... As we all know, Java has eight primitive types i.e. int, short, long, byte, float, double, char, and boolean.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › Double.html
Double (Java Platform SE 7 )
Java™ Platform Standard Ed. 7 ... The Double class wraps a value of the primitive type double in an object.
🌐
Java
download.java.net › java › early_access › loom › docs › api › java.base › java › lang › Double.html
Double (Java SE 25 & JDK 25 [build 1])
The number of bits used to represent a double value, 64. ... The Class instance representing the primitive type double.