What is the difference between Double and double in Java? [duplicate]

-3

I was making a code and by mistake I ended up putting double and the IDE accepted, I always used it with D .

What's the difference between the two?

    
asked by anonymous 09.12.2018 / 18:38

2 answers

5

double is a primitive data type (that is, it is not created by reference, in other words, it is not an object). Not being an object, you do not have access to a number of features that the manipulation of objects offers, perhaps the most important being the conversion of a double value to text ( String ) and the use of collections ( ArrayList , Set , etc.), since they only deal with objects and not primitives.

To make it possible for primitive types to make use of the resources that objects have at their disposal, in Java, for each primitive type there is a class whose only function is to receive the value of it and "pack" the value of that primitive with an object . These classes are called wrappers (packers). As in Java, the default class naming is the first letter of the uppercase letter, the wrapper class of the primitive double is the Double .

    
10.12.2018 / 12:04
11

The Double class involves a value of the primitive type double in an object. An object of type Double contains a single field whose type is double .

In addition, this class provides several methods for converting a double to a String and a String into a double , as well as other constants and methods useful when dealing with a double . p>

Source: link

In summary, the classe Double is a wrapper . See more about Wrappers here .

    
09.12.2018 / 18:56