Hello
can you guys tell me if there is a difference between these two sections of code
Code:x = Double.parseDouble( xChars );
Code:x = ( Double.valueOf( xChars ) ).doubleValue();
Printable View
Hello
can you guys tell me if there is a difference between these two sections of code
Code:x = Double.parseDouble( xChars );
Code:x = ( Double.valueOf( xChars ) ).doubleValue();
About "Double.valueOf":
Returns a Double object holding the double value represented by the argument string s.
If s is null, then a NullPointerException is thrown.
Leading and trailing whitespace characters in s are ignored. The rest of s should constitute a FloatValue as described by the lexical rule:
FloatValue:
Signopt NaN
Signopt Infinity
Signopt FloatingPointLiteral
where Sign and FloatingPointLiteral are as defined in ยง3.10.2 of the Java Language Specification. If s does not have the form of a FloatValue, then a NumberFormatException is thrown. Otherwise, s is regarded as representing an exact decimal value in the usual "computerized scientific notation"; this exact decimal value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type double by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value. Finally, a Double object representing this double value is returned.
To interpret localized string representations of a floating-point value, use subclasses of NumberFormat.
While "Double.parseDouble":
Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double
thanks for the reply
i geuss the two sections of code are equivalent?
i guess this is not possible
i guess xChars is not an object, but a value in this code?Code:double xChars
xChars.doubleValue()
Correct, in java there is a difference between primitive data types (int, char, boolean, short...) and class objects (Integer, Character, Boolean, Short...) Not like in Visual Languages
& double is a primitie data type.
would Integer be an object holiding an integer value?
Yes, exactly, it holds int value with some methods to use
thanks