• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replace Double.parseDouble();

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got am information that
Double.parseDouble(); is very slow
is any boddy know any replacement for this function
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can use public Double valueOf()


 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic