|
-
Jun 22nd, 2006, 12:29 PM
#1
Thread Starter
Frenzied Member
double object's method comparison
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();
Last edited by vb_student; Jun 24th, 2006 at 10:33 AM.
-
Jun 22nd, 2006, 04:28 PM
#2
Re: double object's method comparison
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 23rd, 2006, 01:32 PM
#3
Thread Starter
Frenzied Member
Re: double object's method comparison
thanks for the reply
i geuss the two sections of code are equivalent?
i guess this is not possible
Code:
double xChars
xChars.doubleValue()
i guess xChars is not an object, but a value in this code?
-
Jun 23rd, 2006, 04:01 PM
#4
Re: double object's method comparison
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 23rd, 2006, 06:07 PM
#5
Thread Starter
Frenzied Member
Re: double object's method comparison
& double is a primitie data type.
would Integer be an object holiding an integer value?
-
Jun 23rd, 2006, 07:31 PM
#6
Re: double object's method comparison
Yes, exactly, it holds int value with some methods to use
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 24th, 2006, 10:33 AM
#7
Thread Starter
Frenzied Member
Re: double object's method comparison
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|