• Post Reply Bookmark Topic Watch Topic
  • New Topic

Replace Double.parseDouble();

 
Anoop Krishnan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got am information that
Double.parseDouble(); is very slow
is any boddy know any replacement for this function
 
jatin rai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use public Double valueOf()

 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, valueOf() and parseDouble() are virtually identical - the difference is that the former returns a double (primitive) and the latter returns a Double (wrapper class). In fact valueOf() calls the exact same code as parseDouble() internally, and then it creates a Double wrapper for the result, so it will take slightly longer.
Anoop- have you tested parseDouble() yourself to see if it's really too slow for your application? In general I don't see any reason why it should be overly slow; I've never noticed a problem with it. Are you parsing a lot of values, that the time it takes to parse is noticeable? I don't think there's really a good alternative in the standard libraries. You might be able to write something yourself that parses faster than the standard library, if you can assume some additional restrictions on hte input - e.g. no leading or trailing spaces or zeroes; no values that might overflow a double variable; maybe others. But I doubt you'd improve on it by a whole lot, and it would be easy to introduce new bugs into the algorithm. Good luck...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!