• Post Reply Bookmark Topic Watch Topic
  • New Topic

new Double() or parseDouble  RSS feed

 
Sahil Sharma
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If i want to do some calculations in a for loop using doubles and converting some of the values to double before doing the calculation what is the better approach performance wise:

Double d = 250/new Double(someValue);

or

Double d 250/ Double.parseDouble(someValue);

Thanks
 
Suranga Nath Kasthurirathne
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer the first method.. much much cleaner.. and also parseDouble() takes a string value... why bother with that when you have the first option ?

cheers ....
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, for computation, I'd cast to the primitive.

That is:



I'd only use the class Double in the event that I was converting to/from a String or needed a non-primitive object. java.lang.Double is nullable, double is not.

Then again, I'd also run benchmarks if it really mattered.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!