This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes confusion in parseDouble and parseInt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "confusion in parseDouble and parseInt" Watch "confusion in parseDouble and parseInt" New topic
Author

confusion in parseDouble and parseInt

Niki Nono
Ranch Hand

Joined: Mar 20, 2005
Posts: 256
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???


Life called,so here I am.<br />Cheers<br />Niki.:-)
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
parseDouble() trims the white space, parseInt() does not.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
Have you checked out Aspose?
 
subject: confusion in parseDouble and parseInt
 
jQuery in Action, 3rd edition