Win a copy of Functional Reactive Programming this week in the Other Languages 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic