Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion in parseDouble and parseInt

 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am a bit stumped on why
Double.parseDouble(" 244") gives me 244 as output and
Integer.parseInt(" 244") gives NumberFormatException at runtime.


following is sample code




can anyone please explain???
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
parseDouble() trims the white space, parseInt() does not.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation for the standard Java API should be your first resource when encountering such questions. Find the docs for the version of Java you are using and bookmark them. Learn to navigate it so you can find these odd idiosyncracies between similar methods and other invaluable information about the classes and methods that are available.

Layne
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic